Continuing the theme . You need to make a function so that other users can sort by the field they need. I do it like this:
function sort_page($pages,$field,$sort) { usort($pages,function($a,$b) { return ($a[$field] - $b[$field]); }); return $pages; }
In the template I call as follows:
{$pages = sort_page($pages,'field_price','desc')}
I send an array, the field by which you want to sort, and the sort order (in the example is not used). If i write
return ($a['field_price'] - $b['field_price']);
Then everything works fine, if as in the example, it does not work. As if the function inside usort does not accept other variables. How to be?