admin管理员组文章数量:1435859
I am trying to order category by acf field value. How can I achieve this using acf filed value?
$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;
I am trying to order category by acf field value. How can I achieve this using acf filed value?
$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;
Share
Improve this question
edited Mar 20, 2019 at 11:49
Aftab
1,3919 silver badges19 bronze badges
asked Mar 20, 2019 at 7:36
AbheeAbhee
1035 bronze badges
5
|
1 Answer
Reset to default 0Use 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;
本文标签: categoriesHow to use acf field value to order category
版权声明:本文标题:categories - How to use acf field value to order category? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745672870a2669678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'toc_category' . '_' . $cat->term_id
. – Gufran Hasan Commented Mar 20, 2019 at 8:17order
. – Gufran Hasan Commented Mar 20, 2019 at 8:18