Ok, guys, turns out getting the post count by counting the number of posts beloning to the category is not the way to go. Here’s the working code:
global $post;
$categories = get_categories();
foreach ( $categories as $c ) {
$counts[$c->term_id] = $c->count;
}
That gives you a $counts array populated with category id and count number, which you can asort, reverse and slice.
Does anyone know why counting the number of posts beloning to a category doesn’t give you a proper category count?