How to filter entities by price (higher/lower than $VALUE)?

Greetings,

Right now i am displaying entities with the list_entities_by_metadata(...) function.

I am wondering how i could filter entities by let's say price (metadata). The price would be filtered as higher than $VALUE or lower than $VALUE.  Would this be possible with the standard Elgg methods? Or would i have to use SQL ? I have seen the function elgg_get_entity_metadata_where_sql(...), but i cannot get either heads or tails from the description, so i don't know if that would be a possible solution, or how to make it work.

I have been searching the discussions and haven't been able to find a solution as of yet. I aplologize if there is already a topic on this matter.

Thanks for any replies in this matter.

  • Use: elgg_list_entities_from_metadata($options)

    http://reference.elgg.org/engine_2lib_2metadata_8php.html#a273ceac041577846e90e9f5a50151b36

     

    $options is an array of arguments including

    order_by_metadata => NULL|ARR (array('name' => 'metadata_text1', 'direction' => ASC|DESC, 'as' => text|integer), Also supports array('name' => 'metadata_text1')

     

  • @Matt - Thank you for the quick reply, i really appreciate it!

    But isn't order_by_metadata located only in get_entities_from_metadata and the recent elgg_get_entities_from_metadata. I am using list_entities_from_metadata to display them.

  • I think there's some confusion. If you're using Elgg 1.7 you should use get and list functions that start with elgg_. If you look up the functions at the reference site (which has been linked to a few times) you'll see that list_entities_from_metadata() says:

    Deprecated:

    1.8 Use elgg_list_entities_from_metadata

    This means you should use elgg_list_entities_from_metadata(). The docs for that function say that it accepts all the options list_entities_from_metadata() accepts.

  • @Brett - Thank you for clearing that up. I am still trying to figure out the details regarding the specifics of

    order_by_metadata => NULL|ARR (array('name' => 'metadata_text1', 'direction' => ASC|DESC, 'as' => text|integer), Also supports array('name' => 'metadata_text1')

    what are 'name' and 'as' respectively in this context if i may ask?

  • Hello,

    i still lack the knowledge to display for example only entities that have the metadata 'price' equal or lower that let's say 30.

    I have been looking at the references but i can not figure it out.

    Appreciate any help in this matter.

  • <?php
    $ObjectsEntities = elgg_list_entities_from_metadata
    (
        array
        (
            metadata_name_value_pairs =>
            array(
                 array('name'=>'<YOUR PRICE METADATA NAME>','value'=>"<YOUR PRICE METADATA VALUE>",'operand'=>'<=')
            )
            , 'types' => "<YOUR ENTITY TYPE>"
            , 'limit' => 10
            , 'full_view' => FALSE
        )
    )
    ;
    ?>

  • @DhrupDeScoop - Thank you! That did the job perfectly! :)

  • @DhrupDeScoop you rock thanks for the post