Home › Forums › General Issues › Order get_terms by ACF field, even if the field is not set › Reply To: Order get_terms by ACF field, even if the field is not set
I recently built something similar
This is my usort function for ordering terms
function sort_vid_terms_by_menu_order($a, $b) {
if ($a->sort_order == $b->sort_order) {
return 0;
} elseif ($a->sort_order < $b->sort_order) {
return -1;
} else {
return 1;
}
} // end function sort_terms_by_menu_order
and this is how I get the terms
$args = array(
'taxonomy' => $taxonomy,
'hide_empty' => true,
'parent' => $parent,
'hierarchical' => true
);
$terms = get_terms($args);
if (!empty($terms)) {
foreach ($terms as $index => $term) {
$term->sort_order = intval(get_field('sidebar_menu_order', $term));
}
usort($terms, 'sort_vid_terms_by_menu_order');
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.