Programming TipsWordPress Tips

WordPress Get Total Post Count For All Posts

I’m not in the habit of writing posts with answers that can be told in only two lines, but to this day I still see an awful lot of posts on Stack Overflow and the WordPress forums to warrant it. Getting the total post count in WordPress is really just about as simple as it gets.

How To Get Post Count In WordPress

$count_posts = wp_count_posts();
echo $count_posts->publish;

Variations For Getting Post Count In WordPress

You can alternate publish with any of the other post statuses, like draft to get the post counts of non-publishes posts.

Get Post Count Of Custom Post Types In WordPress

You can also get just the counts of custom post types or pages by specifying the post type in the wp_count_posts() first parameter.

$count_posts = wp_count_posts('the-custom-post-type');
echo $count_posts->publish;

Leave a Reply

Allen Gingrich

Author Allen Gingrich

Allen has worked on the web for over a dozen years. Like many young entrepreneurs, he began with a small workspace in his basement, where he eventually formed Ideas and Pixels. The rest, well, is history. Allen enjoys fine wines, weight training, and beautiful, semantic code.

More posts by Allen Gingrich

Leave a Reply