2

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

2 Answers 2

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

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

3
  • Not one comment, but max one from each post
    – user23068
    Nov 6, 2012 at 19:40
  • Could you be more specific? Are you trying display one comment from all posts?
    – Dom
    Nov 6, 2012 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, 2012 at 10:20
1
<?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

3
  • 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, 2012 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 Nov 7, 2012 at 7:36
  • A loop seems like the way to go, I'll have to explore into that.
    – user23068
    Nov 7, 2012 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.