0
votes

I have a custom post type called meeting and I want to add its edit and list screens as separate submenu items under a custom menu item slug meetings_settings.

Here is my current menu setup

add_action('admin_menu', 'wf_meetings_menu');
function wf_meetings_menu() {
    add_menu_page('Meetings', 'Meetings', 'manage_options', 'meetings_menu', 'meetings_settings');
    add_submenu_page('meetings_menu', 'Meetings Settings', 'Settings', 'manage_options', 'meetings_menu_settings', 'meetings_settings');
    // meetings list screen goes here
    add_submenu_page('meetings_menu', 'All Meetings', 'All Meetings', 'manage_options', 'meetings_menu_all', 'meetings_all');
    // meetings edit screen goes here
    add_submenu_page('meetings_menu', 'New Meeting', 'New Meeting', 'manage_options', 'meetings_menu_new', 'meetings_new');
}

From research I see you can add a custom post type as a submenu by setting show_in_menu => 'edit.php?post_type=meeting' on the custom post type, and then setting the draw function for the submenu item to 'edit.php?post_type=meeting'. I'm a little confused with this part, because wouldn't that only include the edit screen for that post type? There are TWO screens for a custom post type: the edit screen and the list screen (plus categories and tags but I don't need those in this case).

How do you differentiate between the two and add both the edit and list screens for a custom post type as submenu items of a regular admin menu item like above?

1

1 Answers

1
votes

The first parameter of the add_submenu_page function is the parent slug which in this case is 'edit.php?post_type=meeting' in your scenario you'd want to add a custom link that links to the post type edit screen. so you would add a function in functions.php that would add the link manually

add_action('admin_menu', 'meetings_admin_menu');
function meetings_admin_menu() {
    global $submenu;
    $new_url = 'post-new.php?post_type=meeting';
    $all_url = 'edit.php?post_type=meeting';
    $submenu['meetings_menu'][] = array('New Meeting', 'edit_posts', $new_url);
    $submenu['meetings_menu'][] = array('All Meetings', 'edit_posts', $all_url);
}

note: the second paramater in the $submenu array() is permissions. change accordingly

and now you only need your add_menu_page function.