1

I have been trying really hard to find an answer to resolve a issue I am having but not successfull so far. So If there is a solution exist, Please just give me the link / reference to it. Let me explain the issue step by step.

I am developing a plugin for wordpress. It has several "Custom Post Types" but let's just take two for example here.

First one is "Book"

$labels = array(
    'name'                  => __('All Books', 'text-domain'),
    'singular_name'         => __('Book', 'text-domain'),
    'menu_name'             => __('Books', 'text-domain'),
    'name_admin_bar'        => __('Book', 'text-domain'),
    'add_new'               => __('New Book', 'text-domain'),
    'add_new_item'          => __('Add New Book', 'text-domain'),
    'new_item'              => __('New Book', 'text-domain'),
    'edit_item'             => __('Edit Book', 'text-domain'),
    'view_item'             => __('View Book', 'text-domain'),
    'all_items'             => __('All Books', 'text-domain'),
    'search_items'          => __('Search Books', 'text-domain'),
    'not_found'             => __('No books found.', 'text-domain'),
    'not_found_in_trash'    => __('No books found in Trash.', 'text-domain'),
);
    
$args = array(
    'labels' => $labels,
    'public' => true,
    'has_archive' => false,
    'publicly_queryable' => true,
    'menu_icon' => 'dashicons-portfolio',
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => array('slug' => 'book'),
    'hierarchical' => true,
    'menu_position' => null,
    'supports' => array('title', 'editor'),
    'exclude_from_search' => true,
    'show_in_rest' => true,
    'capability_type' => 'book',
    'map_meta_cap' => true,
);

register_post_type('book', $args);

Another is "Places"

$labels = array(
    'name'                  => __('All Places', 'text-domain'),
    'singular_name'         => __('Place', 'text-domain'),
    'menu_name'             => __('Places', 'text-domain'),
    'name_admin_bar'        => __('Place', 'text-domain'),
    'add_new'               => __('New Place', 'text-domain'),
    'add_new_item'          => __('Add New Place', 'text-domain'),
    'new_item'              => __('New Place', 'text-domain'),
    'edit_item'             => __('Edit Place', 'text-domain'),
    'view_item'             => __('View Place', 'text-domain'),
    'all_items'             => __('All Places', 'text-domain'),
    'search_items'          => __('Search Places', 'text-domain'),
    'not_found'             => __('No places found.', 'text-domain'),
    'not_found_in_trash'    => __('No places found in Trash.', 'text-domain'),
);
    
$args = array(
    'labels' => $labels,
    'public' => true,
    'has_archive' => false,
    'publicly_queryable' => true,
    'menu_icon' => 'dashicons-portfolio',
    'show_ui' => true,
    'show_in_menu' => 'edit.php?post_type=book',
    'query_var' => true,
    'rewrite' => array('slug' => 'place'),
    'hierarchical' => true,
    'menu_position' => null,
    'supports' => array('title', 'editor'),
    'exclude_from_search' => true,
    'show_in_rest' => true,
    'capability_type' => 'place',
    'map_meta_cap' => true,
);

register_post_type('place', $args);

As you can see that in the second post type "place", the "show_in_menu" argument is set to be displayed in first post type in the wordpress admin menu as recommended by wordpress docs. Now let's say we have a user who is only able to manage these two post types and nothing else in the wordpress admin area, so all permissions of these two post types are assigned to a user (with User Role Editor plugin).

Everything is just working fine but the problem is happening with capabilities. The first post type being the parent (on display level only) is not giving issues at all. But with the second post type the user is unable to "Create" post type even though the button for "Create" is appearing on the post type's list screen.

If I am separating the second post type in the admin menu by setting the "show_in_menu" argument to true then user can "Create" or if the user is assigned an additional default wordpress capability of "edit_posts", he can also create.

So, I need a way for these two posts be together in one menu and don't show show the user anything else in the admin other than these two post types.

Looking forward for any resolution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.