Query to fetch the recent comments – WordPress

<?php
global $wpdb;
$commentQuery = "SELECT * from $wpdb->comments WHERE comment_approved= '1' 
ORDER BY comment_date DESC LIMIT 0 ,5";
$comments = $wpdb->get_results($commentQuery);
foreach ($comments as $comment) {
$url = '<a href="'. get_permalink($comment->comment_post_ID).
'#comment-'.$comment->comment_ID .'">';
?>
<li><?php echo $url; ?><?php echo $comment->comment_author; ?> On 
<?php echo get_the_title($comment->comment_post_ID); ?></a></li>
<?php } ?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *