Get comments for specific post outside the loop

Home Forums PHP Development Get comments for specific post outside the loop

This topic contains 4 replies, has 3 voices, and was last updated by  tritandominic 3 years, 8 months ago.

  • #965


    Participant

    Trying to get comments for a post, but I can’t get it to work. Here’s the code:
    <?php
    $comments = get_comments('$post_id');
    foreach($comments as $comment) : ?>
    <div>
    <ul>
    <li>
    <?php echo ($comment->comment_content); ?>
    </li>
    </ul>
    </div>
    <?php endforeach; ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • #969

    Martin Carlsson
    Keymaster

    Looks ok.
    What is it that dosen’t work? Are no comments displayed? Are the wrong comments displayed?

    #970

    Mitchelle
    Participant

    I get all comments, not just those for the post I want.

    #984

    Martin Carlsson
    Keymaster

    I see you have quotes around the $post_id varible. Remove them, and if it still doesn’t work, do a var_dump on your $post_id varible.
    Perhaps its null or something.

    #1091

    tritandominic
    Participant

    Have you tried reverting to default configuration?

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.