我正在尝试按acf字段值排序类别。如何使用acf字段值实现这一点?

$categories = get_categories(\'taxonomy=toc_category\');
$sorted_cats = array();
foreach($categories as $cat){
$ordr = get_field(\'order\', \'toc_category\' . \'_\' . $cat->term_id);
$sorted_cats[$ordr] = $cat;
echo \'<pre>\';
print_r($cat);
echo $cat->name; // it not returns expexted output
}
krsort($sorted_cats);
return $sorted_cats;
最合适的回答,由SO网友:Tanmay Patel 整理而成
Use this code.
$categories = get_terms(\'toc_category\');
$sorted_cats = array();
foreach($categories as $cat){
$ordr = get_field(\'order\', \'toc_category_\'.$cat->term_id);
$sorted_cats[$ordr] = $cat->name;
}
krsort($sorted_cats);
return $sorted_cats;