1

I have created a menu page with the following code:

add_menu_page('My Page', 'My Page', 'administrator', 'admin.php?page=my_page', array($this, 'my_page'));

And now I want to use custom post types on this page, also I want to create a few other custom post types, that are displayed as subpages from this page.

I can't really find how to do this, anyone who can give me some suggestions?


Edit: What I want to achieve is the following:

A menu group with the following pages:

Tournaments - Tournaments - Matches - Players - ...

All of the subpages are custom post types. I need a neat way to achieve this.

4
  • What happened when you used add_submenu_page() with the same trick? Feb 27, 2015 at 11:10
  • What do you exactly mean? Can you provide examples?
    – user68296
    Feb 27, 2015 at 11:11
  • Sorry! I misunderstood your question. Why do you need to create a menu page first then to assign a post type there? A post type creation will automatically provide you that, isn't that? Can you please edit your question, clarify your mission? Feb 27, 2015 at 11:12
  • You should be able to provide the parent page slug to the show_in_menu value when you register your CPT.
    – JMB
    Feb 27, 2015 at 11:17

1 Answer 1

2

You should be able to provide the slug of your top level page (admin.php?page=my_page) when registering your CPT(s):

register_post_type( 'matches',
    array(
        'labels' => array(
                'name' => __( 'Matches' ),
                'singular_name' => __( 'Match' )
         ),
    'public' => true,
    'has_archive' => true,
    // Add your page slug to 'show_in_menu'
    'show_in_menu' => 'admin.php?page=my_page'
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.