Restrict a user to view other post except he created


To restrict a specific user to view other post except he created need to add the below code to your theme function file. Put the below code to function.php and you are done.

function posts_for_current_author($query) {
        global $pagenow;
    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;
    if( !current_user_can( 'manage_options' ) ) {
       global $user_ID;
       $query->set('author', $user_ID );
     }
     return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');

Tags:

Comments & Responses

You must be logged in to post a comment.