get_terms
does not support a post__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:
function gto_forced_order($orderby) {
$orderby = "FIELD(t.term_id,5,1,4)";
return $orderby;
}
add_filter('get_terms_orderby','gto_forced_order');
$terms = get_terms('category');
var_dump($terms);
Or…
function gto_forced_order($pieces) {
$pieces['orderby'] = "ORDER BY FIELD(t.term_id,5,1,4)";
return $pieces;
}
add_filter('terms_clauses','gto_forced_order');
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.
function gto_forced_order($pieces,$taxonomies,$args) {
if (in_array('category',$taxonomies)) {
$pieces['orderby'] = "ORDER BY FIELD(t.term_id,5,1,4)";
}
return $pieces;
}
add_filter('terms_clauses','gto_forced_order',1,3);
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.