How to Show Comments for Authors’ Own Posts Only in WordPress

How to Show Comments for Authors’ Own Posts Only in WordPress

If you have Authors on your site, one added complication they face in the admin area is seeing comments on posts that they did not write.

If you would like to fix that and show them only comments on posts they have authored, you can place the following bit of code into your functions file. (Appearance > Theme Functions – functions.php)

If you would like to make your own simple plugin for this code, you can learn how to do that here.

{code type=php}
function wps_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’, ‘wps_get_comment_list_by_user’);
}
{/code}

In this example, the first comment from “Bob” is not on a post from this author, but the author sees it anyway.

all-comments2

After adding the code/self-made plugin, that comment will disappear from the list of this author.

author-comments

(Original source for this code found here.)

Photo BigStock Photo: Male Comment Icon