categories - How to use acf field value to order category?
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;
最新文章
- 谷歌继续封死华为后路,Mate 30无法安装谷歌服务
- 大本营不保?美国安卓系统激活量超iOS
- 谷歌无人驾驶汽车或将带来下一轮失业大潮
- python - How to solve this TensorflowTensorboard compatibility problem? - Stack Overflow
- schema - TALLY XML API ISSUE - Stack Overflow
- docker compose - Issues with Using CapSolver Extension in Selenium Grid for reCaptcha v2 - Stack Overflow
- How do you use partitions in Music Player Daemon (MPD) - Stack Overflow
- javascript - The side menu bar(sticky) is overflowing unless I scroll - Stack Overflow
- Teradata: How can I trim a column for leading zeros and trailing spaces? - Stack Overflow
- c# - Add button to DetailRowTemplate in Blazorise DataGrid - Stack Overflow
- python - Unable to Fetch Data from PostgreSQL on Databricks - Connection Attempt Failed - Stack Overflow
- visual studio code - Cant use pip install on pytorch Python 3.13.01, MacOS Sonoma 14.6.1 - Stack Overflow
- Blender Python Script isn't positioning meshes right from the image - Stack Overflow
- c++ - Casting std::optional inferior type - Stack Overflow
- flutter - How to adjust code formatting when formatting the document - Stack Overflow
- wordpress - XML Reader Not Found in cPANEL php v8.3 - Stack Overflow
- powerbi - How do I use GenerateSeries with a dynamic end value? - Stack Overflow
'toc_category' . '_' . $cat->term_id
. – Gufran Hasan Commented Mar 20, 2019 at 8:17order
. – Gufran Hasan Commented Mar 20, 2019 at 8:18