Skip to content

Instantly share code, notes, and snippets.

@alexmangini
Last active August 29, 2015 14:24
Show Gist options
  • Save alexmangini/d589a36ff30fb07367a0 to your computer and use it in GitHub Desktop.
Save alexmangini/d589a36ff30fb07367a0 to your computer and use it in GitHub Desktop.
List categories by post count — WordPress
<?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