盛夏的果实 发表于 2021-7-15 15:52:31

WordPress后台显示相关用户文章相关联评论的方法

本文实例讲述了WordPress后台显示相关用户文章相关联评论的方法。分享给大家供大家参考。具体分析如下:
将下面的代码添加到当前主题的 functions.php 文件即可,代码如下:

代码如下://后台只显示当前用户文章关联的评论
function wpdx_get_comment_list_by_user($clauses) {
      if (is_admin()) {
                global $user_ID, $wpdb;
                $clauses['join'] = ", wp_posts";
                $clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
      };
      return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wpdx_get_comment_list_by_user');
}
注:如果你的WordPress所使用的数据库前缀不是默认的 wp_,请将第 5 、6 行中的 wp_ 修改为你的WordPress站点的数据库前缀.
希望本文所述对大家的WordPress建站有所帮助。

文档来源:脚本之家https://www.jb51.net/cms/265686.html
页: [1]
查看完整版本: WordPress后台显示相关用户文章相关联评论的方法