2

I want to show the 3 most recent comments and have a small div underneath that shows how many replies each comment has (count how many comments where comment_parent => comment_ID).

I do this by looping through each parent comment (comment_parent => 0) and then for each parent comment, use get_comments(comment_parent => $comment_ID).

Unfortunately the comment_parent is ignored on the inner-loop of each comment and I get returned an array of comments where comment_parent => 0. Why is comment_parent getting ignored?

<!-- DISPLAY RECENT COMMENTS -->
<?php $args = array(
                    'number' => 3,
                    'status' => 'approve',
                    'comment_parent' => 0
                    );
$recent_comments = get_comments($args);
foreach($recent_comments as $recent_comment){
    echo '<div class="front-page-comments">';
    echo $recent_comment->comment_content;
    echo '</div>';
    $parent_comment_id = $recent_comment->comment_ID;
    $comment_meta_args = array(
                               'status' => 'approve',
                               'comment_parent' => intval($parent_comment_id),
                               'number' => 3
                               );
    $replies = get_comments($comment_meta_args);
    echo '<div class="front-page-comment-meta">';
    echo $parent_comment_id . '<br />';
    echo '<pre>';
    print_r($replies);
    echo '</pre>';

    //echo $replies . 'Replies';
    echo '</div>';
}

?>

1 Answer 1

2

In the wordpress codex function reference for comments, it looks like the parameter for the parent is not comment_parent but just parent. Which is weird and inconsistent because the return values are prefixed with comment_.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.