Sometimes, you need to restrict users to only be able to see their own posts in the site’s backend.
You cannot do this using Toolset Access rules, so a custom code is needed.
Use Toolset to add the following code to your site, to a
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
add_filter( 'pre_get_posts', 'tssnippet_view_own_posts_in_admin' );
function tssnippet_view_own_posts_in_admin( $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;
}