wordpress - 如何在 WordPress 帖子中仅显示评论作者(未注册)的未批准评论?

标签 wordpress wordpress-theming

我收到评论

$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/

相关文章:

WordPress:如何获取单个帖子的 rss feed?

css - 如何在 wordpress 中使用自定义小部件

html - 图像叠加在图像之前加载一瞬间

php - Wordpress 初学者 - style.css 不影响 page.php

php - Wordpress 环境和极高的使用率 (PHP-FPM)

css - wordpress子主题两次加载子样式,没有父样式

css - 样式子菜单 CSS

css - 在 WordPress TwentyTen 主题的子项中覆盖 CSS 未生效

javascript - 使用 javascript 和 jquery 在某个符号后更改格式

css - 仅在一页上从类中删除样式?