Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created April 25, 2013 12:38
  • Star 24 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tommcfarlin/5459391 to your computer and use it in GitHub Desktop.
[WordPress] Add a custom post type menu as a child of an existing custom post type menu.
<?php
// Define the 'Portfolio' post type. This is used to represent galleries
// of photos. This will be our top-level custom post type menu
$args = array(
'labels' => array(
'all_items' => 'Gallery',
'menu_name' => 'Portfolio',
'singular_name' => 'Gallery',
'edit_item' => 'Edit Gallery',
'new_item' => 'New Gallery',
'view_item' => 'View Gallery',
'items_archive' => 'Gallery Archive',
'search_items' => 'Search Portfolio',
'not_found' => 'No galleries found',
'not_found_in_trash' => 'No galleries found in trash'
),
'supports' => array( 'title', 'editor', 'author', 'revisions' ),
'menu_position' => 5,
'public' => true
);
register_post_type( 'portfolio', $args );
// Next, we'll define a second custom post type called 'Locations' where we could
// potentially display a list of locations that are used as part of our portfolio.
// This custom post type will be added as a submenu to the 'Portfolio' menu
$args = array(
'labels' => array(
'all_items' => 'Locations',
'menu_name' => 'Locations',
'singular_name' => 'Location',
'edit_item' => 'Edit Location',
'new_item' => 'New Location',
'view_item' => 'View Location',
'items_archive' => 'Location Archive',
'search_items' => 'Search Locations',
'not_found' => 'No locations found.',
'not_found_in_trash' => 'No locations found in trash.'
),
'supports' => array( 'title', 'editor', 'revisions' ),
'show_in_menu' => 'edit.php?post_type=portfolio', // This is where we tell WordPress to add 'Locations' as a submenu
'public' => true
);
register_post_type( 'location', $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment