How do I get taxonomy terms by ID in a specific order. Below is my code and I thought if I passed get_terms
the arguments to with ID and post_in but I am not seeing the results I thought I should.
$args_terms = array(
'post_in' => array(47, 48, 49, 46 , 50, 5),
'orderby' => 'post_in',
'parent' => '0'
);
$custom_post_type = 'menu-food';
$taxonomy = 'menu-food-categories';
$taxonomy_terms = get_terms( $taxonomy, $args_terms);
get_terms
does not support apost__in
argument and I don’t see any other argument that will let you force an order. You can, however, accomplish this with one fof at least two filters:Or…
That
5,1,4
are the term IDs. The query will sort in whatever is given there.Those filters will both work globally, changing every call to
get_terms
, but by using the other arguments the filters offer you can control where the filter runs.If you add
var_dump($pieces,$taxonomies,$args)
to the top of that callback you can see what you have to work with (though it will make a mess– debugging only).It is similar with
get_terms_orderby
but the parameters are a bit different.