我收到评论
$comments = get_comments(array(
'post_id'=>get_the_ID(),
'order'=>'ASC',
));
我通过在循环中检查$comment->comment_approved
来显示评论。
但我想向发送评论的人显示未经批准的评论。
我的解决方案是在所有评论(批准与否)的循环中检查 $_SERVER['HTTP_USER_AGENT'] == $comment->comment_agent
,但我不确定这是否足够?!或者必须检查其他值?
最佳答案
这是我发现的最佳解决方案:
// geting comments of post
$comments = get_comments(array(
'post_id'=>get_the_ID(),
'order'=>'ASC',
));
foreach($comments as $comment){
// if unapproved comment is not commented by this user continue...
if(!$comment->comment_approved && $_SERVER['HTTP_USER_AGENT'] != $comment->comment_agent){
continue;
}
// if unapproved comment is commented by this user show the message.
if(!$comment->comment_approved && $_SERVER['HTTP_USER_AGENT'] == $comment->comment_agent){
echo "Your comment is awaiting moderation";
}
// show the comment
echo $comment->comment_content . '<br>';
}
关于wordpress - 如何在 WordPress 帖子中仅显示评论作者(未注册)的未批准评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40548062/