Following is my code which I am using to display comments of posts in a loop (Custom Post Types). I would like to display only latest 3 comments. Kindly help me to limit comments.

<?php  foreach (get_comments() as $comment): ?>
    <div><span class="author-name"><?php echo $comment->comment_author; ?> said:</span> <span class="author-cmnt">"<?php echo $comment->comment_content; ?>".</span></div>
<?php endforeach; ?>

2 Answers 2


I don't usually work with comment so my suggestion is untested, but I see that get_comments() receives an array of args.

Try this:

$comments = get_comments(array("number" => 3))

and instead of your foreach loop:

foreach ($comments as $comment):


My answer to this is to use something like this:

$args = ['number' => 3];
$comments = get_comments( $args );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.