Home / admin / Display comments in admin to authors own posts only
  • How to Display comments in admin to authors own posts only

    display-comments-admin-authors-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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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');
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    comment_post, current_user_can, user_can, get_comment, add_filter, is_admin, wp,
  • This is pretty cool, thanks for sharing.

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

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

  • Hey, thanks for your amazing site!

    • No problem enjoy the wordpress code snippets

  • Where do I copy this code ?

    • 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!

        • 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 ???