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.
<?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
Thank you for your sharing.
I managed to implement some mine sites. Thanks very much