I created three new custom post types and they all work fine for my admin user. A User with the Editor role can see the menu items in the admin, but when they click one it says:
"Sorry, you are not allowed to access this page."
It's been driving me crazy, any idea what I am missing?
// The custom function MUST be hooked to the init action hook
add_action( 'init', 'handbook_noodles_post_type', 0 );
// A custom function that calls register_post_type
function handbook_noodles_post_type()
{
// Set various pieces of text, $labels is used inside the $args array
$labels = array(
'name' => 'Noodles\'s Handbook',
'singular_name' => 'Noodles\'s Page',
'add_new' => __( 'Add New Page' ),
'add_new_item' => 'Add New Page',
'edit_item' => 'Edit Page',
);
// Set various pieces of information about the post type
$args = array(
'labels' => $labels,
'description' => 'Noodles\'s Handbook Pages',
'public' => true,
'exclude_from_search' => true,
'query_var' => false,
'show_in_menu' => 'employee_handbook.php',
'supports' => array('title', 'editor', 'page-attributes'),
'hierarchical' => true,
'has_archive' => true,
'capability_type' => 'post',
'map_meta_cap' => true
);
register_post_type( 'noodles-handbook', $args );
}
I created three new custom post types and they all work fine for my admin user. A User with the Editor role can see the menu items in the admin, but when they click one it says:
"Sorry, you are not allowed to access this page."
It's been driving me crazy, any idea what I am missing?
// The custom function MUST be hooked to the init action hook
add_action( 'init', 'handbook_noodles_post_type', 0 );
// A custom function that calls register_post_type
function handbook_noodles_post_type()
{
// Set various pieces of text, $labels is used inside the $args array
$labels = array(
'name' => 'Noodles\'s Handbook',
'singular_name' => 'Noodles\'s Page',
'add_new' => __( 'Add New Page' ),
'add_new_item' => 'Add New Page',
'edit_item' => 'Edit Page',
);
// Set various pieces of information about the post type
$args = array(
'labels' => $labels,
'description' => 'Noodles\'s Handbook Pages',
'public' => true,
'exclude_from_search' => true,
'query_var' => false,
'show_in_menu' => 'employee_handbook.php',
'supports' => array('title', 'editor', 'page-attributes'),
'hierarchical' => true,
'has_archive' => true,
'capability_type' => 'post',
'map_meta_cap' => true
);
register_post_type( 'noodles-handbook', $args );
}
I suspect the problem is not when you register the post type but when you create the menu pages.
When you call add_submenu_page() make sure that the $capability argument is correct. In your case you want 'edit_posts':
$capability = 'edit_posts';
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug );