Is this code within the Loop so that the post ID is available? If so, you can get the comments for the current post like this:
$sql = "
SELECT DISTINCT comment_post_ID, comment_author, comment_date_gmt, comment_approved, SUBSTRING(comment_content,1,100) AS com_excerpt
FROM $wpdb->comments
WHERE comment_approved = '1'
AND comment_post_ID = $post->ID
ORDER BY comment_date_gmt DESC
LIMIT 5";
(@alxvallejo)
12 years, 5 months ago
In a function I have a call to the $wpdb:
I want to add to only select comments from the current post though. I feel like I’ve tried everything to define the post_id and the comment_post_id. Any suggestions?