This is what I’m trying to do:
if number of posts is greater than 20 -> display link to another page (which shows all posts)
if number of posts is less than 20 -> don’t display the link
So far I’ve been able to return the number of posts using
$count_posts = wp_count_posts('inventory');
$published_posts = $count_posts->publish;
but I don’t know where to go from here, any suggestions?
If I remember right count of posts in category is stored persistently in category object. So use
get_category()
or variation of it and fetch the number out of object.Example code (not tested):
You can access that from the object itself:
another simple way to do this is using get_terms. I use this when I need to display a category list AND I need to ignore a category which has a set minimum number of posts.