Title: Sort by count with &#8220;basic&#8221;
Last modified: November 28, 2021

---

# Sort by count with “basic”

 *  [Kip Kniskern](https://wordpress.org/support/users/kip-kniskern/)
 * (@kip-kniskern)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/sort-by-count-with-basic/)
 * I am creating a WordPress page for a semi full list of our (many, many) tags.
   Along with the list, I would like to create a “most popular tags” section, where
   the top tags are sorted by their post counts, and limited to say the top 25.
   
   Is this possible? Using count_order only orders within a letter (ie, most popular
   tags starting with A, most popular tags starting with B, etc). I would like to
   order tags by count while using the basic=”yes” option, showing a list of most
   popular tags by count.

Viewing 1 replies (of 1 total)

 *  Plugin Author [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * (@tugbucket)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/sort-by-count-with-basic/#post-15111372)
 * count_order works as designed. The plugin separates all results alphabetically
   and groups them by their respective letter. The basic option doesn’t change this.
   They are still grouped by letter.
 * My plugin isn’t designed to do what your are wanting.
 * The below code will return a list of your 25 most used (by tag count) tags and
   sort them alphabetically within each count.
 * for example:
    Potato (3) Apples (2) Bananas (2) Celery (1) Raisin (1) Spinach(
   1) etc…
 *     ```
       <?php
       	$tags = get_terms(array(
       		'taxonomy' => 'post_tag',
       		'orderby' => 'count',
       		'order' => 'DESC',
       		'number' => 25
       	));
       	$groups = array();
       	foreach ($tags as $key => $item) {
       		$groups[$item->count][$key] = $item;
   
       	}
       	sort($groups, SORT_NUMERIC);
       	$grouped = array();
       	foreach($groups as $group){
       		usort($group, function ($a, $b) {
       			return $a->slug <=> $b->slug;
       		});
       		$grouped[] = $group;
       	}
       	$groups = array();
       	foreach($grouped as $g){
       			$groups = array_merge($groups, $g);
       	}
       	echo '<ul>'."\n";
       	foreach($groups as $tag){
       		echo '<li><a href="'.get_tag_link($tag->term_id).'">'.$tag->name.' ('.$tag->count.')</a></li>'."\n";
       	}
       	echo '</ul>'."\n";
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Sort by count with “basic”’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/multi-column-tag-map_9e2525.svg)
 * [Multi-column Tag Map](https://wordpress.org/plugins/multi-column-tag-map/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multi-column-tag-map/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multi-column-tag-map/)
 * [Active Topics](https://wordpress.org/support/plugin/multi-column-tag-map/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multi-column-tag-map/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multi-column-tag-map/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/sort-by-count-with-basic/#post-15111372)
 * Status: not resolved