how to list entities by metadata with 2 options

I have a plugin that I have created and I am trying to list out entities using metadata... this is my current function that works fine:

list_entities_from_metadata_multi(array('update_type' => '1','status'=>'1'), 'object','updates', 0, 10,false, false, true);

what I really want to do is list all entities that have update_type = 1 OR 2 ... but I am not sure how to do it... I have tried to find online, but just can't figure it out.

appreciate your help


  • why don't you release your plugin to the elgg community ? that is the best way to get the whole community involved with debugging and extending any plugin ;-)

  • well, that was my plan, when it was finished... but its pretty specific to my needs, but ok... here it comes

    any ideas on my question?

  • it can be difficult to look at just snippets of code for debugging, usually the whole code is better because then people can actually run the code and see how it behaves/misbehaves.

  • it has been uploaded:

    but my main question is about this code:

    $area2 .= list_entities_from_metadata_multi(array('update_type' => '2','status'=>'0'), 'object','updates', 0, 1,false, false, false);       
            $area2 .= elgg_view_title(elgg_echo('updates:class:current:bs'));
            $area2 .= list_entities_from_metadata_multi(array('update_type' => '1','status'=>'0'), 'object','updates', 0, 1,false, false, false);
            $area2 .= elgg_view_title(elgg_echo('updates:class:past'));
            $area2 .= list_entities_from_metadata_multi(array('update_type' => '1','status'=>'1'), 'object','updates', 0, 10,false, false, true);       


    Everything works, just not the way I want... the first list_entities lists for update_type 2, and the second list_entities lists for update_type 3... all i want to do is list entites for both 1 and 2 at the same time, like using an OR operator, but I just dont know how to do it.

  • lolz..

    so you want to condense 6 lines of code into 2 ?  hehhh.



    function allows for supplying arrays of metadata names and values in one call. i do not have an exact sample code here right now, but we've coded that many times in the past.

    i'll post an example once i find it.


  • no, I dont want to combine all that into two lines... I just want to change that last list_entities call to something like this:

    $area2 .= list_entities_from_metadata_multi(array('update_type' => '1' || '2','status'=>'1'), 'object','updates', 0, 10,false, false, true); 

    but the '1' || '2' doesn't seem to work.

  • $num_messages =
            array('metadata_name_value_pairs' => array
                        'toId' => $_SESSION['user']->guid,
                        'readYet' => 0,
                        'msg' => 1
                    ,'types' => 'object'
                    ,'subtypes' => 'messages'
                    ,'owner_guid' => $_SESSION['user']->guid
                    ,'limit' => 9999

  • but, in your example, I don't see anything like  'readYet' => 0 OR 1

    which is what I am trying to do

  • take a look at the documentation for elgg_get_entities_from_metadata(). It explains how to do the OR (it ends up using the SQL syntax IN). You can do the whole thing through a call to elgg_list_entities_from_metadata().

  • the "OR" functionality is implicit in the array metadata_name_value_pairs of metadata names and values ;-). sample code is from live site ;-P