Forums

  • # November 5, 2011 at 12:20 am

    I am trying to get post specific comments. The code below does return comments, but it gets them all. How can I get those specific to the post?




    < ?php
    //$args = array('order' => 'ASC');
    $comments = get_comments('$post_id');
    foreach($comments as $comment) :
    ?>


    • < ?php echo ($comment->comment_content); ?>



    < ?php endforeach; ?>

    # November 7, 2011 at 1:44 pm

    Well, I would probably just use the code from the twentyeleven theme and use the have_comments loop. But, if you want to go this way, you could grab the post ID first, then put it into get_comments. Something like this:

    $current = $post->id;

    Then you can use:

    get_comments($current);
    # November 7, 2011 at 2:06 pm

    Your code does not pass the correct parameter to the function. You care just getting all comments because of that.

    < ?php
    //$args = array('order' => 'ASC');
    $comments = get_comments('$post->id');
    foreach($comments as $comment) :
    ?>


    • < ?php echo ($comment->comment_content); ?>



    < ?php endforeach; ?>

    I changed the ‘$post_id to $post->id that should fix the error.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag