Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I currently developing a wordpress plugin that is using two custom post types. What I want to know here: is it possible to add a custom post type menu as another custom post type's sub menu?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Yes. When you register your post type you need to set show_in_menu to the page you would like it displayed on.

Adding a custom post type as a sub-menu of Posts

Here we set the "movies" post type to be included in the sub-menu under Posts.

register_post_type( 'movies',
    array(
            'labels' => array(
                    'name' => __( 'Movies' ),
                    'singular_name' => __( 'Movie' )
            ),
    'public' => true,
    'has_archive' => true,
    'show_in_menu' => 'edit.php'
    )
);

If you have a taxonomy registered to the custom post type it will need to be added to the page as well.

In add_submenu_page() the first argument is the page to assign it to and the last is the menu slug.

add_action('admin_menu', 'my_admin_menu'); 
function my_admin_menu() { 
    add_submenu_page('edit.php', 'Genre', 'Genre', 'manage_options', 'edit-tags.php?taxonomy=genre'); 
}  

Adding a custom post type as a sub-menu of another custom post type

To add the pages to another custom post type include the post type's query string parameter along with the page names.

To add the CPT Movies and its taxonomy Genre under the post type Entertainment adjust the code like this.

edit.php becomes edit.php?post_type=entertainment

edit-tags.php becomes edit-tags.php?taxonomy=genre&post_type=entertainment

register_post_type( 'movies',
    array(
            'labels' => array(
                    'name' => __( 'Movies' ),
                    'singular_name' => __( 'Movie' )
            ),
    'public' => true,
    'has_archive' => true,
    'show_in_menu' => 'edit.php?post_type=entertainment'
    )
);

add_action('admin_menu', 'my_admin_menu'); 
function my_admin_menu() { 
    add_submenu_page('edit.php?post_type=entertainment', 'Genre', 'Genre', 'manage_options', 'edit-tags.php?taxonomy=genre&post_type=entertainment'); 
}
share|improve this answer
    
Hi, thanks. It works. But the sub menu cpt lost its submenu. –  Ari Susanto Aug 18 '13 at 18:00
    
I've update my answer with a way to include taxonomies. –  epilektric Aug 21 '13 at 11:58
    
Hi thanks you! I had found the way to do it! But may be yours will give a better result! –  Ari Susanto Aug 21 '13 at 12:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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