I want a function to calculate the amount of posts inside a Wordpress blog that's aware if you're searching in a category, confirmed tag or even the whole blog.

I am keen to prevent spinning for each different circumstance and wish to make certain I recieve off on the reliable path. Relatively recent to Wordpress any help appreciated.


If you wish to retrieve a count of all of the posts inside a blog, use wp_count_posts(). To obtain publish counts from the specific category, perform a count() on the call to get_posts() using the category ID specified like a parameter.


$posts = get_posts('category=1');
$count = count($posts);

echo $count;

Regrettably WordPress' wordpress_count_posts() function will not count a category's posts. It'll only count different publish types, i.e posts, pages, drafts, as well as in 3., custom publish types.

Supplies a template function: WordPress › Count Posts « WordPress Plugins. Could borrow the code from this and integrate it to your theme's functions.php file.