Sort custom taxonomy terms order by both count and name

I am working on a custom taxonomy sorting to make popular terms. The requirement is to sort by popular posts by post count and also I need to sort terms by name to get it alphabetical order.

Here is my code

$args = array(
'hide_empty' => 0 ,
'orderby' => 'count',
'orderby' => 'name',
'parent'=> $cat_main->term_id
);

$terms = get_terms('question_type',$args);

Another condition is that orderby count has to be DESC and orderby name has to be ‘ASC’

Any suggestions?

1 Answer
1

This won’t be possible via the function itself or to be exact by just providing parameters/arguments. You have to do this via hooks to alter the default behavior, I think. You should take a closer look at at least two, they are: get_terms_orderby and/or terms_clauses.

Leave a Comment