For our ‘Posts’ type, our Contributors can see only their own posts, which is what we want. But for our custom post types, Contributors can see every post, including drafts. Is there a way to limit their view of custom posts so they only see their own posts like it is in the ‘Posts’ type?
Edit:
Maybe I wasn’t as clear about my problem. I want the Contributors to be able to see all of the custom types (Videos, Images, etc), but within each custom type I want them to be able to see only their own posts. So if they look at the CPT Videos, for example, they would only be able to see their own posted videos, not a post by someone else.
You need to use the action hook pre_get_posts
.
See the comments for details and modify the Custom Post Type(s) to your own:
add_action( 'pre_get_posts', 'filter_cpt_listing_by_author_wpse_89233' );
function filter_cpt_listing_by_author_wpse_89233( $wp_query_obj )
{
// Front end, do nothing
if( !is_admin() )
return;
global $current_user, $pagenow;
wp_get_current_user();
// http://php.net/manual/en/function.is-a.php
if( !is_a( $current_user, 'WP_User') )
return;
// Not the correct screen, bail out
if( 'edit.php' != $pagenow )
return;
// Not the correct post type, bail out
if( 'portfolio' != $wp_query_obj->query['post_type'] )
return;
// If the user is not administrator, filter the post listing
if( !current_user_can( 'delete_plugins' ) )
$wp_query_obj->set('author', $current_user->ID );
}
You’ll notice that the post count All|Published|Drafts needs to be corrected.
See the solution here.