Last active
August 29, 2015 14:24
-
-
Save alexmangini/d589a36ff30fb07367a0 to your computer and use it in GitHub Desktop.
List categories by post count — WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Reorders get_categories() to list categories by | |
* the most posts to least. | |
* | |
* Example use: listing the most popular categories | |
* on your blog. print_r() function to see results. | |
*/ | |
function kol_most_active_categories( $args = null ) { | |
$cats = get_categories( $args ); | |
foreach ( $cats as $cat => $fields ) { | |
$count[$cat] = $fields->count; | |
} | |
array_multisort( $count, SORT_DESC, $cats ); | |
return $cats; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment