How to display total posts and comments in WordPress

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

Click to rate this tutorial!
[Total: 0 Average: 0]

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.

<?php
$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

Click to rate this tutorial!
[Total: 0 Average: 0]

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

Leave a Reply

Your email address will not be published.