wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Display comments in admin to authors own posts only

wordpress snippet

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.

snippet :  PHPcopy
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');
}
source →

Did you like this post? If so please share it with your friends. Thanks!

  • http://www.leachcreative.com/ Andrew Leach

    This is pretty cool, thanks for sharing.

    • http://wpsnipp.com Kevin Chard

      No problem Andrew,

  • http://www.iblognet.com/ Sahil

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

    • http://wpsnipp.com Kevin Chard

      Glad to hear it, lots of stuff on the way :)

  • http://twitter.com/maxisanchez Maximiliano Sánchez

    Hey, thanks for your amazing site!

    • http://wpsnipp.com Kevin Chard

      No problem enjoy the wordpress code snippets

  • http://www.facebook.com/behroozkarami1 Behrooz Karami

    Where do I copy this code ?

    • http://wpsnipp.com Kevin Chard

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

      • Monisha

        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.

  • Pingback: How to Filter Comments in the WordPress Admin for Quicker Moderation - WPMU.org

  • Dominic

    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.

    • Dominic

      I meant database prefix

      • Ismael

        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!

      • Ismael

        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!

        • http://wpsnipp.com Kevin Chard

          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.

  • batman

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