How to get total comments count for a post?

WordPress provide with the following function:

<?php wp_count_comments( ); ?> 

The above code gets the total count of all comments present on the site. If we need to get the total comments count of a particular post then we can use following code:

<?php
$comments_count = wp_count_comments( $post_ID );
echo "Comments in moderation: " . $comments_count->moderated . "<br />"; 
echo "Comments approved: " . $comments_count->approved . "<br />";
echo "Comments in Spam: " . $comments_count->spam . "<br />";
echo "Comments in Trash: " . $comments_count->trash . "<br />";
echo "Total Comments: " . $comments_count->total_comments . "<br />";
?>

Here the $post_ID argument is the ID of the post. Simple!!!

2017-08-17T06:58:17+00:00 By |WordPress|