Count parent comments and replies separately

Image Widget Review - select your image

This snippet will count parent comments and replies separately. Add the first snippet to the functions.php of your wordpress theme then add the second snippet in the single.php or the theme you will to display the number of comments and comment replies.

Code Snippet:

function c_parent_comment_counter($id){
global $wpdb;
$query = "SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE `comment_approved` = 1 AND `comment_post_ID` = $id AND `comment_parent` = 0";
$parents = $wpdb->get_row($query);
return $parents->count;

Code Snippet:

$number_of_parents = c_parent_comment_counter($post->ID);
$number_of_children = $post->comment_count – $number_of_parents;

echo "parents: ".$number_of_parents;
echo "children: ".$number_of_children;

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!