I’m having a wired problem with WordPress. Below is my code for an events post type, it works without the capabilities but when the capabilities are added all the default roles (admin, editor, etc…) cant use the post type. The admin role is only able to see the custom taxonomies.
I have a custom user role with “edit_events => true” for the user role that is able to submit events for review. This is what I want, but the built in roles can’t see the post type!
I’ve tried just about every capabilities tutorial I could find, they all seem to be pretty much the same and I can’t how any of them differ from my code.
function register_custom_event_type() {
$labels = array(
'name' => _x('Events', 'event'),
'singular_name' => _x('Event', 'event'),
'add_new' => _x('Add New', 'event'),
'add_new_item' => _x('Add New Event', 'event'),
'edit_item' => _x('Edit Event', 'event'),
'new_item' => _x('New Event', 'event'),
'view_item' => _x('View Event', 'event'),
'search_items' => _x('Search Events', 'event'),
'not_found' => _x('No events found', 'event'),
'not_found_in_trash' => _x('No events found in Trash', 'event'),
'parent_item_colon' => _x('Parent Event:', 'event'),
'menu_name' => _x('Events', 'event'),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail', 'author'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'event',
'capabilities' => array(
'read_post' => 'read_event',
'publish_posts' => 'publish_events',
'edit_posts' => 'edit_events',
'edit_others_posts' => 'edit_others_events',
'delete_posts' => 'delete_events',
'delete_others_posts' => 'delete_others_events',
'read_private_posts' => 'read_private_events',
'edit_post' => 'edit_event',
'delete_post' => 'delete_event',
),
'map_meta_cap' => true
);
register_post_type('event', $args);
}
add_action('init', 'register_custom_event_type');
I found a work around in the end.
I thought the default WordPress Roles would have the same capabilities for the post type as a normal post, but for some reason they don’t.
Adding the capabilities manually seems to work.
make sure to include
'map_meta_cap' => true,
when registering your custom post type also set the capability type correctly eg.'capability_type' => array('event', 'events'),
then use the User Role Editor Plugin and click the permissions as you see fit for the individual roles – done!After setting
'map_meta_cap' => true
and setting'capability_type' => array('event', 'events')
you might also need to add the capabilities:register_post_type() WordPress Codex
thats a strange problem. it should work. the following will work for you (note i just copied paste my code so some of my code creeped in)
Something to do with the way you are calling it. Dont know where. sometimes its easier just to start again 🙂
Good Luck
Had the same issue. Custom capability_type in custom post type, logged in as user with new user role is no problem, but the admin did not see the articles in CPT.
Installing “User Role Editor” did the trick. Acivating, Reload, Deactivating, Deleting. Still works.
When registering the post type, add the supports tag enabling editor like this:
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' )