Last updated on March 30th, 2022 at 08:55 am

This tutorial will show you how to get the total posts and comments count in WordPress without plugin. All you have to do is edit your theme say footer or header or sidebar as you wish 🙂 and then add the following lines.

$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts);
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcomms) $numcomms = number_format($numcomms);

If you would like to see just the post count demo check this Display total post count in WordPress

2 thoughts on “How to display total posts and comments in WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *