I'm creating a plugin in WordPress. I've created a custom post type called "relationlink". With some custom capabilities. Here is my code for the creation of the custom post type:
register_post_type( 'relationlink', array(
'labels' => ...an_array_with_label...,
'description' => __( 'Description.', 'ovasconnect_churches' ),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'relationlink' ),
'capabilities' => array(
'create_posts' => 'edit_relationlink',
'edit_post' => 'edit_relationlink',
'read_post' => 'view_relationlink',
'delete_post' => 'delete_relationlink',
'edit_posts' => 'edit_relationlink',
'edit_others_posts' => 'edit_relationlink',
'publish_posts' => 'edit_relationlink',
'read_private_posts' => 'edit_relationlink',
'delete_posts' => 'delete_relationlink',
'delete_private_posts' => 'delete_relationlink',
'delete_published_posts' => 'delete_relationlink',
'delete_others_posts' => 'delete_relationlink',
'edit_private_posts' => 'edit_relationlink',
'edit_published_posts' => 'edit_relationlink',
),
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title' ),
'map_meta_cap' => false
));
I'm not displaying it in the menu. And created my own menu with the link to edit.php?post_type=relationlink
like this:
add_action( 'admin_menu', function() {
add_menu_page('My PluginName', 'My PluginName', 'edit_relationlink', 'parentslug', [$this, 'informationPage'] );
add_submenu_page( 'myparentslug', 'Information', 'Information', 'edit_relationlink', 'parentslug', [$this, 'informationPage'], '', '1' );
add_submenu_page( 'myparentslug', 'RelationLinks', 'RelationLinks', 'edit_relationlink', 'edit.php?post_type=relationlink', null, '', '2' );
});
This works just fine. I can edit the post_type. But when i'm clicking on Add new, my permission is denied: Sorry, you are not allowed to access this page.
The strange thing is, when i set show_in_menu
to true
its works just fine.
I've also tried to set show_in_menu
to parentslug
but then i can edit but also can't add.
My Question
Has anyone an idea how to show only a link in the menu to edit, in my custom menuitem, but so, that i can add items aswell?
(Edit)
Just found out, that if you create a menu item that has the url post-new.php?post_type=relationlink
it all works just fine. But i don't want it in my menu...
It seems to be needed in the menu to add a custom post type. Any thought on that?