Languages: English • Italiano • (Add your language)
Retrieve a total comment count for a site or post.
<?php wp_count_comments( post_id ); ?>
Returns an object with values approved, moderated, spam, trash, total_comments.
Retrieve comment count for a site.
<?php $comments_count = wp_count_comments(); echo "Comments for site <br />"; 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 />"; ?>
<?php $comments_count = wp_count_comments( 2492 ); echo "Comments for post 2492 <br />"; 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 />"; ?>
Since 2.5.0
wp_count_comments() is located in wp-includes/comment.php
.
Count Tags: wp_count_posts(), wp_count_terms(), wp_count_comments(), count_users()