我有一个自定义的选择查询,它从特定类别中提取指定数量的帖子,并按最新评论的顺序显示它们。问题是,如果一篇帖子同时包含了这两条最新评论,它将显示两次。我希望它能以某种方式检测重复的帖子并将其排除,只显示最新的评论。
$sql =
"SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID,
comment_author, comment_date, comment_approved, comment_type,comment_author_url,
SUBSTRING(comment_content,1,100) AS com_excerpt
FROM $wpdb->term_taxonomy as t1, $wpdb->posts, $wpdb->term_relationships as r1, $wpdb->comments
WHERE comment_approved = \'1\'
AND comment_type = \'\'
AND ID = comment_post_ID
AND post_password = \'\'
AND ID = r1.object_id
AND r1.term_taxonomy_id = t1.term_taxonomy_id
AND t1.taxonomy = \'category\'
AND t1.term_id IN ($inlist)
ORDER BY comment_date DESC LIMIT 4";
有什么想法吗?