Home Forums ACF PRO Ordering taxonomy terms


Ordering taxonomy terms

  • Hello,

    I have a custom post type with a taxonomy ‘departments’. I am using the basic foreach loop, but the terms are coming out in a random order, and I’d like to order them alphabetically, but I can’t figure out how to do it.

    Is there any way that I can order the terms that are coming out?


  • I figured it out… for anyone that’s looking for the answer:

    $terms = get_field('portfolio');
                                     usort($terms, function($a, $b) {return strcmp($a->name, $b->name);});
                                     if( $terms ):
                                         echo '<ul>';
                                         foreach( $terms as $term ):
                                           echo '<li>';
                                             $name = $term->name;
                                             echo $name;
                                           echo '</li>';
                                         echo '</ul>';
  • ACF returns them in the order that they are selected, which may be why they seem random.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.