Number of unpublished comments for each post

How can I show the number of unpublished comments for each post in a theme?
I have searched, but I found nothing.

I also need to show published comments number for each post.

Answer

I wonder if you’re looking for the wp_count_comments() function.

To retreive comment count statistics for the whole site, you can use:

$comments_count = wp_count_comments();

or for a given post ID:

$comments_count = wp_count_comments( 123 );

It will return an object with the following attributes:

$comments_count->moderated 
$comments_count->approved 
$comments_count->spam
$comments_count->trash 
$comments_count->total_comments 

Check the Codex for more information and examples.

Attribution
Source : Link , Question Author : user3159807 , Answer Author : birgire

Leave a Comment