• Resolved savegothamcity

    (@savegothamcity)


    I’m trying set the value “post_id” to the ID of the current post and pass it into the get_comments() function. I tried the following but it doesn’t work. Can anybody tell me what I’m doing wrong?

    <?php global $post; echo $post->ID; ?>
    <?php
    $comments = get_comments(‘post_id=$post->ID’);
    foreach($comments as $comm) :
    echo($comm->comment_author);
    echo($comm->comment_date);
    echo($comm->comment_content);
    endforeach;
    ?>

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • $comments = get_comments($post->ID);

    Thread Starter savegothamcity

    (@savegothamcity)

    Thanks for the reply. I just tried $comments = get_comments($post->ID); and it did not work as it returns all comments for all posts.

    I only want to get the comments for a specific post. When I try $comments = get_comments(‘post_id=24’); I get all the comments just for post 24. How do I get it to work dynamically where I can it to return the comments just for the current post?

    Thread Starter savegothamcity

    (@savegothamcity)

    Anybody out there have any suggestions? I’m really struggling with this one.

    Can you show the complete code for the file where you’re placing this… i’ll then test and try to replicate…

    I just had a similar problem tonight when trying take action if there were approved comments for a post. Solved it like this:

    <? php
    
    $comments_array = get_comments('post_id=' . $id . ',status=approve');
    $comments_approved  = count($comments_array);
    ?>
    
    <?php if (0 != $comments_approved){ ?> <code><em>blah blah</em></code><?php } ?>

    I solved this problem like this:

    $comments = get_comments('number=6&status=approve&post_id=$id');
      foreach($comments as $comm) :
        echo '<li>';
    	echo($comm->comment_author);
    	echo ':';
    	echo($comm->comment_content);
      	echo '</li>';
    endforeach;
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Passing parameter to get_comments function’ is closed to new replies.