I have the following functions. WordPress functions, but this is really a PHP question. They sort my $term
objects according to the artist_lastname
property in each object's metadata.
I want to pass a string into $meta
in the first function. This would let me reuse this code as I could apply it to various metadata properties.
But I don't understand how I can pass extra parameters to the usort callback. I tried to make a JS style anonymous function but the PHP version on the server is too old (v. 5.2.17) and threw a syntax error.
Any help - or a shove towards the right corner of the manual - gratefully appreciated. Thanks!
function sort_by_term_meta($terms, $meta)
{
usort($terms,"term_meta_cmp");
}
function term_meta_cmp( $a, $b )
{
$name_a = get_term_meta($a->term_id, 'artist_lastname', true);
$name_b = get_term_meta($b->term_id, 'artist_lastname', true);
return strcmp($name_a, $name_b);
}
PHP Version: 5.2.17