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

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

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

  • 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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy