我正在构建一个聊天框,从设置页面中提取评论。它实时更新。
那么我如何获得最近50条评论,但排除我已经显示的评论? get_comments()不允许我排除评论。
这是我希望能够做到的:
// Array of already displayed comment id's
$exclude = array(10, 22, 41, 80);
$args = array (
'number' => 50,
'user_id' => $user_ids,
'post_id' => 57,
'status' => 'approve',
'order' => 'DESC',
'exclude' => $exclude
);
$comments = get_comments( $args );
任何人都知道实现“排除”参数的方法,或类似的东西?
答案 0 :(得分:0)
您可以使用wpdb类
尝试原始sql查询SELECT
*
FROM
`wp_comments`
WHERE `comment_approved` = 1
AND `comment_post_ID`=57
AND `user_id` IN (0, 1, 2)
AND comment_ID NOT IN (10, 22, 41, 80)
ORDER BY comment_date DESC
LIMIT 50
使用wpdb
global $wpdb
$sql="SELECT
*
FROM
$wpdb->comments
WHERE `comment_approved` = 1
AND `comment_post_ID`=57
AND `user_id` IN (". join(',',$user_ids) .")
AND comment_ID NOT IN (". join(',',$exclude) .")
ORDER BY comment_date DESC
LIMIT 50";
$comments=$wpdb->get_results($sql);
if(!empty($comments)){
foreach($comments as $c){
$single_comment=get_comment( $c->comment_ID);
}
}