I need to order parent terms by their children count:
function sort_terms_by_children_count ( $terms ) {
$sort_terms_by_children_count = array();
foreach($terms as $term) {
$count = count (get_terms( $terms, array( 'child_of' => $term->term_id, 'hide_empty' => false, ) ));
$sort_terms_by_children_count[$count] = $term;
}
sort($sort_terms_by_children_count);
return $sort_terms_by_children_count;
}
and use it like:
$terms = get_terms('product_cat');
$terms = $sort_terms_by_children_count($terms);
It doesn't work, outputs only one term.