How to get replies of a comment?

Is there a way to get replies of a comment by its ID? I have searched on google but could not find anything about it.

For example, I have a comment with ID 123

I want to display all the replies that comment ID 123 has.

I have tried something like the following but it did not work:

$args = array(
    'status' => 'approve',
    'ID' => 123,
    'number' => '5',
    'post_id' => 73871,
    'comment_parent' => 0

);
$comments = get_comments($args);

4 Answers
4

As comment_ID is a unique value, there is no need to include the post_id in the arguments.

This works fine for me:

$args = array(
    'status' => 'approve', 
    'number' => '5',
    'parent' => 3194
);
$comments = get_comments($args);

This will return 5 approved comments whose parent is the comment with the comment_ID 3194.

Sample output could be done with something like this:

foreach($comments as $child_comment) {
    echo $child_comment->comment_ID;  
}

Leave a Comment