X

Display Number Of Posts

Have you ever wanted to display the total number of Wordpress posts? How about displaying the total number of posts but excluding specific categories? You'll learn both of these here!

Have you ever wanted to display the total number of WordPress posts? How about displaying the total number of posts but excluding specific categories? You’ll learn both of these here!

Place the above code where you’d like to display the total number of published posts.

Code Snippet:

<?php
// All pages
$total = wp_count_posts()->publish;
echo 'Total Posts: ' . $total;

// Pages with a category
$categories = get_categories('exclude=1,2,3');
foreach($categories as $category) {
	$total += $category->count;
}
echo 'Total Posts: ' . $total;
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!