1 - I have a CPT, with 10 posts.

2 - I have 10 users

Q : How can i assign a single post from my CPT, to an unique user ? -> Each user must see only it's assigned post

(Each post will be assigned by the admin of the site)


  • What exactly are you asking? To naively answer: You click into each post and select the desired user as author
    – kero
    Apr 29, 2019 at 12:55
  • User 1 is admin of the website. All other users are only Subscribers (in fact, nobody can whrite content except admin). Each other users had an personnal account. I want the admin to assign a post to a user. With that, each ease can read only its assigned post.
    – WDCreativ
    Apr 29, 2019 at 13:18

3 Answers 3


As Gael mentioned, there's not native WordPress functionality to handle this, but it's not too difficult to achieve.

update_post_meta( $post_id, 'post_subscriber', $user_id );

First, I would create post meta that identifies the user who should have access. You would probably want to set this up with Meta Boxes on the individual pages or using the Settings API. If you have multiple users that need access to the same page, you may want to set this up as User Meta instead which would flip the code below a bit on its head.

Since we're doing 1 user accesses 1 page, the post meta should work fine.

Next, you need to determine whether you want to hide the content of the page only or pretend the page doesn't exist at all. Pick one of these two, not both.

1. Hide the content

We'll filter the page's content, leaving everything else accessible (like the title, featured image, etc. You can replace the content with a message informing the visitor that they're not allowed to see this content, "Nope!" It's a good practice to include a login form along with your message in case the user just forgot to log in ahead of time.

function my_filter_content( $content ) {
    global $post;
    if ( empty( $post ) || ! is_page() ) {
        return $content;

    $post_subscriber_id = get_post_meta( $post->ID, 'post_subscriber', true );
    if ( ! $post_subscriber_id ) {
        return $content;
    $user = wp_get_current_user();
    if ( $user->ID === $post_subscriber_id || user_can( $user->ID, 'administrator' ) ) {
        return $content;
    } else {
        // Content restricted message.
        return 'Nope!';
add_filter( 'the_content', 'my_filter_content', 11 );

2. Redirect the page

Instead of allowing anything to be seen by unauthorized users or the public, this action redirects unauthorized users to a completely separate page where they can be informed they tried to access something by mistake. It's usually a good practice to include a login form on this page in case the user has access, but forgot to log in.

function my_page_template_redirect() {
    // Conditions for targeting the correct content type.
    if ( is_page() ) {
        global $post;
        $post_subscriber_id = get_post_meta( $post->ID, 'post_subscriber', true );
        // Now we know this page has restricted content.
        if ( $post_subscriber_id ) {
            // Check user is logged in.
            if ( is_user_logged_in() ) {
                $user = wp_get_current_user();
                // Check user is allowed access.
                if ( $user->ID === $post_subscriber_id || user_can( $user->ID, 'administrator' ) ) {
            // Redirect user to page explaining why they can't see the content.
            wp_safe_redirect( home_url( '/access-denied/' ) );
add_action( 'template_redirect', 'my_page_template_redirect' );

I want the admin to assign a post to a user. With that, each ease can read only its assigned post.

Not a WP functionality.

You will need to use or create a plugin to achieve that.


I solved the problem doing the following:

  1. You must first add 'author' to your register_post_type, for example
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author' ),
  1. You can then assign a custom post to a user via the quick edit button under Author

  2. add the following to your register_post_type:

'capabilities' => array(                
    // Meta capabilities.
    'edit_post'          => 'edit_staff',
    'read_post'          => 'read_staff',
    'delete_post'        => 'delete_staff',
    // Primitive capabilities used outside of map_meta_cap():
    'edit_posts'         => 'edit_staffs',
    'edit_others_posts'  => 'edit_others_staff',
    'delete_posts'       => 'delete_staffs',
    'publish_posts'      => 'publish_staff',
    'read_private_posts' => 'read_private_staff',
    // Primitive capabilities used within map_meta_cap():
    'read'                   => 'read_staff',
    'delete_private_posts'   => 'delete_private_staff',
    'delete_published_posts' => 'delete_published_staff',
    'delete_others_posts'    => 'delete_others_staff',
    'edit_private_posts'     => 'edit_private_staff',
    'edit_published_posts'   => 'edit_published_staff'
'map_meta_cap' => true
  1. Use a plugin such as https://wordpress.org/plugins/members/ to limit access to these posts checking the above "capabilities"

Depending on what you check, the user will be able to see only his post/s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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