WordPress custom post type capabilities issue

Question

Using WP 5.2.4, I am registering my custom post type with this code:

$args = array(
    'labels'          => $labels,
    'public'          => false,
    'show_ui'         => true,
    'show_in_menu'    => true,
    'query_var'       => true,
    'has_archive'     => false,
    'menu_position'   => null,
    'map_meta_cap'    => false,
    'capability_type' => ['note','notes'],
    'rewrite'         => [ 'slug' => 'note', 'with_front' => false ],
    'supports'        => [ 'editor' ],
    'menu_icon'       => 'dashicons-format-aside',
);

register_post_type( 'note', $args );

Now I want my custom user role to edit/read/delete this post type. I added this caps to my custom user role:

$role = get_role( 'my_custom_role' );

$role->add_cap('read_private_notes');
$role->add_cap('read_note');
$role->add_cap('read');
$role->add_cap('publish_notes');
$role->add_cap('edit_note');
$role->add_cap('edit_notes');
$role->add_cap('edit_others_notes');
$role->add_cap('edit_private_notes');
$role->add_cap('edit_published_notes');
$role->add_cap('edit_notes');
$role->add_cap('delete_note');
$role->add_cap('delete_notes');
$role->add_cap('delete_private_notes');
$role->add_cap('delete_published_notes');
$role->add_cap('delete_others_notes');

Everything is OK for the administrator role and post type item shows in the admin menu. For other roles, it shows the admin menu item but in the post type list page give permission error.

cps show in admin menu

but cpt posts list not showin

How can I fix this problem ?

0
Themesfa 2 years 2020-10-24T18:10:21-05:00 0 Answers 16 views 0

Leave an answer

Browse
Browse