wordpress - Get number of approved comments of post -


in wordpress theme use

<?php $commentscount = get_comments_number(); echo $commentscount; ?> 

to show number of comments of specific post.

the problem is: returns total comment count (including deleted comments etc.) want show number of approved comments. ideas?

use wp_count_comments($postid);

<?php $comments_count = wp_count_comments($postid); echo "comments approved: " . $comments_count->approved ; ?> 

this returns object containing needed data comments.

so can use like,

echo "comments in moderation: " . $comments_count->moderated;  echo "comments approved: " . $comments_count->approved; echo "comments in spam: " . $comments_count->spam; echo "comments in trash: " . $comments_count->trash; echo "total comments: " . $comments_count->total_comments; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -