X

Display comments in admin to authors own posts only

Only show the comments to the authors own posts within the wordpress admin, hide all other comments. This is a great little snippet if you want authors to look after their own comments. Just add this snippet to the functions.php of your wordpress theme and you are ready to go.



Code Snippet:


function wps_get_comment_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
$clauses['join'] = “, “.$wpdb->base_prefix.''posts'';
$clauses['where'] .= '' AND “.$wpdb->base_prefix.''posts.post_author = “.$user_ID.'' AND “.$wpdb->base_prefix.''comments.comment_post_ID = “.$wpdb->base_prefix.''posts.ID'';
};
return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wps_get_comment_list_by_user');
}

Comments  Leave a Reply

  1. please help me
    you are explain how show the comments to the authors own posts
    , I want filter the notify of comments for owner post ? how

  2. You made my day! Thank you so much @wpsnipp:disqus for this valuable tutorial.
    It would be great if we could fix comment counts for contributor profile. Thanks

  3. work in localhost but don’t work in host ???

  4. If the database preifx is something else than wp_ this function won’t work. You should replace wp_ by “.$wpdb->base_prefix.” in join and where clause to fix it.

    1. I meant database prefix

      1. For the life of me I cannot make this work with a different db prefix (my website’s is wp_spanh) I am not at all php literate, so could you please give me the above function with my db prefix in place, so that I can copy / paste it into my functions.php file? I would be eternally grateful!

      2. For the life of me I cannot make this work with a different db prefix (my website’s is wp_spanh) I am not at all php literate, so could you please give me the above function with my db prefix in place, so that I can copy / paste it into my functions.php file? I would be eternally grateful!

        1. Hi Ismael
          I just updated the snippet to work with any prefix should work fine I tested things on the most recent version of wordpress.

  5. How to Filter Comments in the WordPress Admin for Quicker Moderation - WPMU.org July 26, 2012 at 9:45 am

    […] for this useful snippet goes to Kevin Chard of […]

  6. Behrooz Karami July 13, 2012 at 10:32 am

    Where do I copy this code ?

    1. Sorry about that, I update the post. Just add this snippet to the functions.php of your wordpress theme.

      1. But, On pasting the code in theme’s folder/functions.php, the whole comment is disappeared. No comments is visible now. Even, the logged in user’s.

  7. Maximiliano Sánchez July 12, 2012 at 5:48 pm

    Hey, thanks for your amazing site!

    1. No problem enjoy the wordpress code snippets

  8. Ah! 🙂 Thanks .. another great snippet! Very much similar to author post restriction!
    I’m loving your site!!! 🙂

    1. Glad to hear it, lots of stuff on the way 🙂

  9. This is pretty cool, thanks for sharing.

    1. No problem Andrew,

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!