How to display number of replies to wordpress comment?

I have comments and each comment can have any number of replies. After a comment, but before the replies, I want to output how many replies there are. I have thought of two alternative ways to do this:

  1. (more involved in coding, but requires less knowledge of wordpress and the database)
    Make an array with strings and another with ints. Each position of both arrays corresponds to a nesting level in the comment/reply structure. When outputting a comment check what nesting level, or “$depth” you’re on and “retire”, or output, the information stored in the arrays up and until the same nesting level. Then add information of the current nesting level and of course update the int that’s one nesting level above to count the current comment.
    — Somewhat involved, my php skills or debugging tools are not great so this would take a couple of hours to do.

    Read More
  2. (quick but must find some support/function in wordpress that gives me what I want)
    Just find some function in wordpress that displays/returns the number of replies that a comment has (including nested comments)

Related posts

Leave a Reply

3 comments

  1. I accomplished this same thing with a function

    function child_comment_counter($id){
    global $wpdb;
    $query = "SELECT COUNT(comment_post_id) AS count FROM `wp_comments` WHERE `comment_approved` = 1 AND `comment_parent` = ".$id;
    $children = $wpdb->get_row($query);
    return $children->count;
    

    }

    and the actual code to output it:

    <?php echo "( ". child_comment_counter($comment->comment_ID) . " )"; ?>