How to only display all posts to a custom User Role?


I have a custom user role and I want to display all custom website posts to them, without letting them edit/delete them. Right now the custom post doesn’t show up in their dashboard. I know it will show up when I add the edit and delete caps, but I only want them to be able to see their "websites". Ultimately they only get to see the websites that have a custom field that is a relation to the client user. So client1 can only see websites of client1, etc. I have the following code:

// Add the Client user role
function add_client_user_role() {

  $capabilities = array(
        'read'                           => true,
    'read_website'           => true

  add_role( 'client', 'Client' );

    $client = get_role( 'client' );
    $client->add_cap( 'read' );
    $client->add_cap( 'read_website' );


add_action( 'init', 'add_client_user_role', 10 );

How can I achieve this?

EDIT: Ok, I found the hook restrict_manage_posts which I can use to show only the posts assigned to them. Now I still need a way to make sure they show up, without letting them edit the posts. So the custom Post should show up in the dashboard without me giving them caps to edit.

Tom 2 years 2020-10-21T15:10:24-05:00 0 Answers 15 views 0

Leave an answer