我需要按其子项计数排序父项:
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;
}
并像这样使用它:
$terms = get_terms(\'product_cat\');
$terms = $sort_terms_by_children_count($terms);
它不工作,只输出一个术语。