Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>';
}

?>
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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_.

share|improve this answer
    
Thanks, I eventually noticed. –  AlxVallejo Jul 20 '12 at 1:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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