Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
There are solutions about that here, have you searched? It's always nice to reserch before asking, and include any relevant info in the Question. Check this guide: How to Ask. –  brasofilo Mar 4 '13 at 1:38
    
I did search before I asked, but I didn't see anything that dealt with my problem. Most were about blocking custom posts from being shown altogether to lower roles, which is not what I want to do. –  user28330 Mar 4 '13 at 1:51
add comment

1 Answer

up vote 1 down vote accepted

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;
    get_currentuserinfo();

    // 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.

share|improve this answer
    
Perfect, thanks! –  user28330 Mar 4 '13 at 14:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.