Сортировка терминов таксономии по кастомному полю
<?php
$product_cats = get_terms( 'product_cat', $args );
$count = count($product_cats);
for ($i=0; $i<$count; $i++) {
$product_cats[$i]->order_num = get_option('product_cat_order_num_' . $product_cats[$i]->term_id);
}
usort($product_cats, 'my_sort_terms_function');
/**
* TODO: заменить на strcmp
*/
function my_sort_terms_function($a, $b) {
// this function expects that items to be sorted are objects and
// that the property to sort by is $object->sort_order
if ($a->order_num == $b->order_num) {
return 0;
} elseif ($a->order_num < $b->order_num) {
return -1;
} else {
return 1;
}
}
?>