Counting nested comments in the loop

While looping in get_comments() with these args:

$args = array(
'status'    => 'approve',
'order'     => 'DESC',
'number'    => 5
);

I get more than five comments in the loop because of the nested comments.
I want to get the recent 5 comments even if they are parent or nested without disabling the nested feature from the admin panel.

Read More

For example: if the parent comment has 4 nested comments, i wanna just get it with it’s nested and counted as 5 instead of counting other parents.

Related posts

Leave a Reply

1 comment

  1. You could use array_slice to return the first 5 items from the returned wordpress array of comments:

    $yourArray = $returnedCommentsArray;    
    $commentData= array_slice($yourArray, 0, 5)
    

    Where returnedCommentsArray is the array of comments that is returned from your original wordpress call.