How to prevent contributers to see other posts in wordpress

0

How to prevent contributers to see other posts in wordpress

 

How to prevent contributers to see all posts

Open your functions.php file in your theme and if it is not there create there functions.php file in current theme.
Copy and paste the following code .
// PREVENT CONTRIBUTORS FROM SEEING OTHERS POSTS INSIDE ADMIN PANEL
function posts_for_current_author($query) {
global $user_level;
if($query->is_admin && $user_level < 2) {
global $user_ID;
$query->set(‘author’, $user_ID);
unset($user_ID);
}
unset($user_level);
return $query;
}
add_filter(‘pre_get_posts’, ‘posts_for_current_author’);
 
Or try this following one:
 
function posts_for_current_author($query) {
if($query->is_admin) {
global $user_ID;
$query->set(‘author’,  $user_ID);
}
return $query;
}
add_filter(‘pre_get_posts’, ‘posts_for_current_author’);
Or try this one
 
function posts_for_current_author($query) {
global $pagenow;
if( ‘edit.php’ != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( ‘edit_others_posts’ ) ) {
global $user_ID;
$query->set(‘author’, $user_ID );
}
return $query;
}
add_filter(‘pre_get_posts’, ‘posts_for_current_author’);
 
Or try this wordpress plugin ,Mangage posts
 

Leave A Reply

Your email address will not be published.