WordPress-获取评论,但排除一些评论
我正在构建一个聊天框,从一个固定页面中提取评论。它实时更新 那么,我如何才能得到最后50条评论,但不包括我已经显示的评论?get_comments不允许我排除注释 这就是我希望能够做到的:WordPress-获取评论,但排除一些评论,wordpress,comments,Wordpress,Comments,我正在构建一个聊天框,从一个固定页面中提取评论。它实时更新 那么,我如何才能得到最后50条评论,但不包括我已经显示的评论?get_comments不允许我排除注释 这就是我希望能够做到的: // Array of already displayed comment id's $exclude = array(10, 22, 41, 80); $args = array ( 'number' => 50, 'user_id' => $user_ids,
// 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 );
有人知道实现“exclude”参数的方法或类似的方法吗 可以使用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
使用
如何在检索后过滤和删除注释对象?这只需要一个循环。通过查询从数据库获取注释如何?@MKhalidJunaid通过查询从数据库获取注释就可以了。
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);
}
}