Find Most Recent Comments

To find the most recent comments in WordPress use the following code:


$number=30; // number of recent comments desired
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo sprintf(__('%1$s on %2$s'), get_comment_author_link(), '' . get_the_title($comment->comment_post_ID) . ' - ') . $comment->comment_date;
endforeach;
endif;

Leave a Reply