Greetings There is a category loop

<ul class="filter_country"> <?php foreach (get_terms('country') as $cat) : ?> <li><a href="<?php echo get_term_link($cat->slug, 'country'); ?>"> <?php echo $cat->name; ?> </a><span><?php echo $cat->count; ?></span></li> <?php endforeach; ?> </ul> 

How to add sorting by $ cat-> count? Thank.

    1 answer 1

    An array of arguments can be passed to the get_terms function, including the sort parameter:

     $terms = get_terms(array( 'taxonomy' => 'country', 'orderby' => 'count', 'order' => 'ASC' // по возрастанию (значение по умолчанию) или DESC - по убыванию ));