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 have this custom post query to list all the posts within a specific category. For example I have this:

$args = array('cat' => 'home','post_type' => 'post'));
$post_obj = new WP_Query($args);
while($post_obj->have_posts() ) : $post_obj->the_post();
 // do stuff here
endwhile;

So for this page I would like to show the list of posts but also the accompanying comments. I am only showing maximum 2 comments for each post.

Is there a built in function to do this?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

You can use get_comments. Function Reference/get comments

$args = array('cat' => 'home','post_type' => 'post'));
$post_obj = new WP_Query($args);
while($post_obj->have_posts() ) : $post_obj->the_post();
    //display comments
    $comments = get_comments(array(
        'post_id' => $post->ID,
        'number' => '2' ));
    foreach($comments as $comment) {
        //format comments
    }
endwhile;
share|improve this answer
    
Thank you for the help! –  Rick Jan 12 '12 at 21:39
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.