Limit Post Type View By Associated Users

  • Unknown's avatar

    Currently in my WordPress site, I have made it so a user can only see a custom post type if they are the author of it, instead of showing a list of everything. Which is a good start, but I now need to be able to have multiple users associated with my post types. And because of the way the Author field is setup in WordPress, I am not able to have more than one author on one specific post type, which is essentially what I need. My question is, how could I go about making it so that each user can only see the list of custom post types that they are associated with?

    This is the code that I am currently using in my functions.php file:

    function query_set_only_user( $wp_query ) {
    global $current_user;
    if ( is_admin() && !current_user_can(‘manage_options’) ) {
    $wp_query->set( ‘author’, $current_user->ID );
    }
    }
    add_action(‘pre_get_posts’, ‘query_set_only_user’ );

  • Hi there,

    Your site is not hosted on WordPress.com, but using the open source WordPress.org software at another hosting provider. We cannot help with this in the WordPress.com forums.

    Please post in the self-hosted WordPress forums instead for help:

    https://wordpress.org/support/forums

    For this particular question the advanced forum over there is probably your best option.

  • The topic ‘Limit Post Type View By Associated Users’ is closed to new replies.