get_comments() in wordpress ignore the post_id passed to it

I am trying fit wordpress into my website, and instead of creating a theme, I am just making use of the APIs to put the blogs onto my website. I am stuck with getting comments. When I call$comments = get_comments(array(‘post_id=>’.$post->ID,’order’ => ‘ASC’)); I get comments for all posts.
I am not a PHP developer, I am just learning now. I am a java developer actually.. Anyway here’s the code that doesnt work:

<?php global $more; 
$more = -1;
$posts = get_posts('numberposts=10&order=ASC');
$counter=0; 
foreach ($posts as $post) {
    setup_postdata($post);?>

    <div class="article">
        <h2><?php the_title(); ?></h2>
        <div class="clr"></div>
        <h3><?php the_time('F j, Y'); ?></h3>
        <div id="content<?php echo $counter; ?>" class="section sectionborder">
            <?php the_content(); ?>
            <h2>Post ID:<?php echo $post->ID?></h2>

            /**
            * This is where I call get_comments and the post is being passed
            * correctly to it. Since the post ID is printed correctly above. But
            * I am getting comments not related to this post as well
            */

            <?php 
                $comments = get_comments(array('post_id=>'.$post->ID,'order' => 'ASC'));
                echo '<h3>Comments</h3>';
                foreach($comments as $comment) :
                    echo('<div class="comment">'
                        .$comment->comment_content.
                        '<span class="comment-author">-'. $comment->comment_author. '</span>
                        &nbsp;<span class="comment-date">'.date('Y-m-d H:i', strtotime($comment->comment_date)) .'</span>
                    </div>');
                endforeach;
            ?>


        </div>           
        <div id="a<?php echo $counter; ?>">
            <a href="#">Read More</a>                     
        </div>  
    </div>
    <br/>
    <hr/>   
    <?php $counter++; ?>
<?php } ?>  

Related posts

Leave a Reply

1 comment

  1. I don’t know about wordpress, but you have an error here which could cause that problem:

    array('post_id=>'.$post->ID,'order' => 'ASC')
    

    Should be:

    array('post_id' => $post->ID, 'order' => 'ASC')