Guillermo Salas

Send private message

You must be logged in to send a private message.

Group membership

Activity

  • Guillermo Salas added a new discussion topic How can i order by metadata field? in the group Elgg Technical Support
    i have been some trouble when i tried to get data with elgg_get_entities_from_metada, this doesn't have any order, including when i set order by parameter. How can i order a metadata field? i am trying with date field. Regards   
    • As always, use the source. It is well commented.

      In particular, you will want to use the order_by option (defined in elgg_get_entities) or the order_by_metadata option. See the excerpt from engine/lib/metadata.php for that.

      /**
       * Returns entities based upon metadata.  Also accepts all
       * options available to elgg_get_entities().  Supports
       * the singular option shortcut.
       *
       * NB: Using metadata_names and metadata_values results in a
       * "names IN (...) AND values IN (...)" clause.  This is subtly
       * differently than default multiple metadata_name_value_pairs, which use
       * "(name = value) AND (name = value)" clauses.
       *
       * When in doubt, use name_value_pairs.
       *
       * @see elgg_get_entities
       * @see elgg_get_entities_from_annotations
       * @param array $options Array in format:
       *
       *     metadata_names => NULL|ARR metadata names
       *
       *     metadata_values => NULL|ARR metadata values
       *
       *     metadata_name_value_pairs => NULL|ARR (name => 'name', value => 'value', 'operand' => '=', 'case_sensitive' => TRUE) entries.
       *     Currently if multiple values are sent via an array (value => array('value1', 'value2') the pair's operand will be forced to "IN".
       *
       *     metadata_name_value_pairs_operator => NULL|STR The operator to use for combining (name = value) OPERATOR (name = value); default AND
       *
       *     metadata_case_sensitive => BOOL Overall Case sensitive
       *
       *  order_by_metadata => NULL|ARR (array('name' => 'metadata_text1', 'direction' => ASC|DESC, 'as' => text|integer),
       *  Also supports array('name' => 'metadata_text1')
       *
       *  metadata_owner_guids => NULL|ARR guids for metadata owners
       *
       * @return array
       * @since 1.7.0
       */

    • This is along the same question. Could I use metadata fields instead of register/extend for registration? That'd be easier!

    • I have a problem with this. I am trying to sort users by their last name which is a metadata.

      $select_arr['order_by_metadata'] = array( 'name' => "lastname", 'direction' => "asc" );

      But this would show only users who have entered their last name. The other users are not shown. Is there any option to show them too?

  • Guillermo Salas replied on the discussion topic Order by with elgg_get_entities function doesn't work
    Thank Andras... this code works for me now... thanks a lot view reply
  • I have a problem with 'order by' on elgg_get_entities(). Because this doesn't work, i mean, i set this to order by title but it doesn't work for me and i was trying with elgg_get_entities_from_metadata function. Any body can help me with...
    • Title is not stored as metadata, it is part of the core objects_entity table. You'll have to use a custom join and order_by clause. Something like this (untested):

      $calendars = elgg_get_entities_from_metadata(array(

            'types' => 'object',

            'subtypes' => '3key_calendar',

            'owner_guid' => $owner->guid,

            'container_guids' => $owner->guid,

            'joins' => array("INNER JOIN {$CONFIG->dbprefix}objects_entity o ON (e.guid = o.guid)"),

            'order_by' => 'o.title'

         ));

    • Thank Andras... this code works for me now... thanks a lot