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.

Is there a way to limit get_comments results to just the latest comment from every post?

share|improve this question
add comment

2 Answers

get_comments( array( 'number' => '1') );

See http://codex.wordpress.org/Function_Reference/get_comments

share|improve this answer
    
Not one comment, but max one from each post –  Lucian Davidescu Nov 6 '12 at 19:40
    
Could you be more specific? Are you trying display one comment from all posts? –  Dom Nov 6 '12 at 21:55
    
Show the most recent comment, ignore the others from that post, go on to show the next most recent comment from another post, ignore the others from that post and so on. –  Lucian Davidescu Nov 7 '12 at 10:20
add comment
<?php $comments = get_comments(array( 'number' => 1, 'post_id' => get_the_ID() )); ?>

You'll have to specify the ID if you're not in loop

Source: http://codex.wordpress.org/Function_Reference/get_comments

share|improve this answer
    
Same as above, I don't want just one comment but a bunch of them, with no more than one (the most recent) from each post. –  Lucian Davidescu Nov 6 '12 at 19:41
    
Either you can use the above solution in a loop changing the post_id everytime or you'll have to customize the SQL query with comments_clauses filter –  Mridul Aggarwal Nov 7 '12 at 7:36
    
A loop seems like the way to go, I'll have to explore into that. –  Lucian Davidescu Nov 7 '12 at 10:23
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.