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;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745672871a4639513.html
'toc_category' . '_' . $cat->term_id
. – Gufran Hasan Commented Mar 20, 2019 at 8:17order
. – Gufran Hasan Commented Mar 20, 2019 at 8:18