1

In the wordpress admin menu,

I would like to add a custom post type to a submenu item. For example, Menu Item -> Submenu Item -> Custom Post Type

I think I am close, but there may be a simpler way to accomplish this. Or is there a way to accomplish this? The other option I was thinking of is having categories for all subitems. Looking for some advice on how and what I should do here.

This is currently have below:

function.php

Menu Item

function admin_menu_experience() {

     add_menu_page(
         'Experience',
         'Experience',
         'read',
         'test',
         '',
         'dashicons-admin-users',
         40
     );

  }

  add_action( 'admin_menu', 'admin_menu_experience' );

Submenu Item

function admin_submenu_additional_self_test(){
add_submenu_page(
  'test',
  'Test',
  'Test',
  'read',
  'test',
  '',
  'dashicons-admin-users',
  40
);
}
add_action( 'admin_menu', 'admin_submenu_additional_self_test' );

Custom Post Type

function register_subitem_test() {
  $args = array (
    'labels' => array (
      'name' => __( 'Healthcare', 'healthcare' ),
      'singular_name' => __( 'Healthcare', 'healthcare' ),
    ),
    'description' => 'View Available Properties',
    'supports' => array( 'title' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => 'test',
    // 'taxonomies' => array('category'),
    'rewrite' => array('slug' => 'healthcare' ),
    'supports' => array('title', 'editor', 'revisions', 'thumbnail'),
  );
  register_post_type( 'healthcare', $args );
 }
 add_action( 'init', 'register_subitem_test' );
justin.esders
  • 1,316
  • 4
  • 12
  • 28
  • Just to confirm - you are looking to add a 3rd level to the left menu in the admin? – FluffyKitten Sep 21 '17 at 19:06
  • @FluffyKitten yes I am. At least that is what I am trying to do. – justin.esders Sep 21 '17 at 19:07
  • Sorry... I've bad news for you in that case. You can't actually add a 3rd level. You can see my answer to a similar question here for an explanation why: [How can I move admin menu top-level items to submenu](https://stackoverflow.com/questions/45791515/how-can-i-move-admin-menu-top-level-items-to-submenu/45824392#45824392) – FluffyKitten Sep 21 '17 at 19:08
  • @FluffyKitten ok. That is what I assumed, but I couldn't find that answer. Thank you for that. I had another idea in my head if that didn't work so I will go with that. Thank you. – justin.esders Sep 21 '17 at 19:11

1 Answers1

-2

Please set 'menu_position' in CPT to 9 and it will work

// Custom Post Type
function register_subitem_test() {
  $args = array (
    'labels' => array (
      'name' => __( 'Healthcare', 'healthcare' ),
      'singular_name' => __( 'Healthcare', 'healthcare' ),
    ),
    'description' => 'View Available Properties',
    'supports' => array( 'title' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => 'test',
    // 'taxonomies' => array('category'),
    'rewrite' => array('slug' => 'healthcare' ),
    'menu_position'      => 9,
    'supports' => array('title', 'editor', 'revisions', 'thumbnail'),
  );
Rameez Iqbal
  • 507
  • 1
  • 5
  • 24