For some reason I can not create multiple CPT with the same URL structure, for instance I can not get the following to work:
/cpt1/overview
/cpt1/events
/cpt2/overview
/cpt2/events
What ends up happening is the following:
/cpt1/overview
/cpt1/events
/cpt2/overview-2
/cpt2/events-2
I tried the following on a clean install of wp to make sure nothing was messing it up:
add_action( 'init', function()
{
register_post_type( 'cpt1', array(
'labels' => array(
'name' => __('CPT1'),
'singular_name' => _x('Page', 'singular name'),
'add_new' => _x('Add New', 'page'),
'all_items' => __('All Pages'),
'add_new_item' => __('Add New Page'),
'edit_item' => __('Edit Page'),
'new_item' => __('New Page'),
'view_item' => __('View Page'),
'search_items' => _x('Search Pages', 'plural'),
'not_found' => _x('No pages found', 'plural'),
'not_found_in_trash' => _x('No pages found in Trash', 'plural'),
'parent_item_colon' => '',
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'cpt1', 'with_front' => false ),
'show_in_nav_menus' => false,
'hierarchical' => true,
'supports' => array( 'author', 'title', 'editor', 'custom-fields', 'page-attributes', 'revisions' ),
));
} );
add_action( 'init', function()
{
register_post_type( 'cpt2', array(
'labels' => array(
'name' => __('CPT2'),
'singular_name' => _x('Page', 'singular name'),
'add_new' => _x('Add New', 'page'),
'all_items' => __('All Pages'),
'add_new_item' => __('Add New Page'),
'edit_item' => __('Edit Page'),
'new_item' => __('New Page'),
'view_item' => __('View Page'),
'search_items' => _x('Search Pages', 'plural'),
'not_found' => _x('No pages found', 'plural'),
'not_found_in_trash' => _x('No pages found in Trash', 'plural'),
'parent_item_colon' => '',
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'cpt2', 'with_front' => false ),
'show_in_nav_menus' => false,
'hierarchical' => true,
'supports' => array( 'author', 'title', 'editor', 'custom-fields', 'page-attributes', 'revisions' ),
));
} );
Is what I am after possible? and how?
Further Discoveries
1
As I am working with this further .. it seems like wordpress will redirect the following (with out me doing any extra config) ...
/cpt2/overview/
/cpt2/events/
to
/cpt2/overview-2/
/cpt2/events-2/
2
I found the following wp function wp_unique_post_slug (with an available filter) which checks slugs for pages/posts returning a unique slug if it finds a duplicate (appending -2, -3, etc) .. if you look at the function itself, it does do a post_type check but only if the post_type is set as non hierarchical .. otherwise it finds all hierarchical post_types and checks for uniqueness from all (e.g. post, page, book, event .. as an example).