It might be you’re using the category on a custom post type, in that case category_count
won’t include those. There’s another handy value on the $category
-object however: $category->count
. Try replacing this:
$postcount = $thiscat->category_count;
with this
$postcount = $thiscat->count;
The count attribute includes custom post types as well if the custom post type uses standard categories.1