WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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 – user23068 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. – user23068 Nov 7 '12 at 10:20
<?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. – user23068 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. – user23068 Nov 7 '12 at 10:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.