本文實例講述了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');
}
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建站有所幫助。
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。