Sort list by subtype metadata

Hello -

I am modifying a plugin and am trying to sort a subtype by the value of one of its metadata properties. I have been using elgg_list_entities and then order_by to sort the results.

This code below works and does return the results ordered by 'amount' -- but I can't change the direction from ASC to DESC. I'd also like to be able to sort the results to find all the object subtypes that fall within a range of value in the amount field (ie, between 100 and 200).

I have also tried using order_by_metadata and elgg_get_entities_from_metadata -- but with both of those, I wasn't able to sort the results at all.

If anyone can help in identifying the problem with this code or if there is another function I should be using, it'd be a huge help.

Thanks.



$content = elgg_list_entities(array(
    'type' => 'object',
    'subtype' => 'electric',
    'full_view' => true,
    'view_toggle_type' => false,
    'limit' => 10,
    'pagination' => true,
    'order_by' => array(
                    'name' => 'amount',
                    'direction' => 'DESC',
                    'as' => integer)
));