[wp-hackers] Parent/child relationship between two different hierarchical CPTs
Matthew McGarity
matthew at mcgarity.me
Fri Nov 4 18:50:21 UTC 2011
>
> Next question: You say "It doesn't work." The URL routing? If yes, what
> does your reqister_post_type() code look like?
>
$labels = array(
'name' => _x( 'Parks', 'mmc_level1' ),
'singular_name' => _x( 'Park', 'mmc_level1' ),
'add_new' => _x( 'Add New', 'mmc_level1' ),
'add_new_item' => _x( 'Add New Park', 'mmc_level1' ),
'all_items' => _x( 'Parks', 'mmc_level1' ),
'edit_item' => _x( 'Edit Park', 'mmc_level1' ),
'new_item' => _x( 'New Park', 'mmc_level1' ),
'view_item' => _x( 'View Park', 'mmc_level1' ),
'search_items' => _x( 'Search Parks', 'mmc_level1' ),
'not_found' => _x( 'No Parks found', 'mmc_level1' ),
'not_found_in_trash' => _x( 'No Parks found in Trash', 'mmc_level1' ),
'parent_item_colon' => _x( 'Parent Park', 'mmc_level1' ),
'menu_name' => _x( 'Parks', 'mmc_level1' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => '',
'supports' => array( 'title', 'editor', 'author', 'revisions',
'custom-fields', 'comments', 'thumbnail' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => 'mmc_menu',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => array( 'slug' => 'parks', 'with_front' => false ),
'capability_type' => 'page'
);
register_post_type( 'mmc_level1', $args );
$labels = array(
'name' => _x( 'Features', 'mmc_level2' ),
'singular_name' => _x( 'Feature', 'mmc_level2' ),
'add_new' => _x( 'Add New', 'mmc_level2' ),
'add_new_item' => _x( 'Add New Feature', 'mmc_level2' ),
'all_items' => _x( 'eatures', 'mmc_level2' ),
'edit_item' => _x( 'Edit Feature', 'mmc_level2' ),
'new_item' => _x( 'New Feature', 'mmc_level2' ),
'view_item' => _x( 'View Feature', 'mmc_level2' ),
'search_items' => _x( 'Search Features', 'mmc_level2' ),
'not_found' => _x( 'No Features found', 'mmc_level2' ),
'not_found_in_trash' => _x( 'No Features found in Trash', 'mmc_level2' ),
'parent_item_colon' => _x( 'Parent Feature', 'mmc_level2' ),
'menu_name' => _x( 'Features', 'mmc_level2' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => '',
'supports' => array( 'title', 'editor', 'author', 'revisions',
'custom-fields', 'comments', 'thumbnail' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => 'mmc_menu',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => array( 'slug' => 'features', 'with_front' => false ),
'capability_type' => 'page'
);
register_post_type( 'mmc_level2', $args );
In the above code, I've been playing back and forth with the rewrite
argument, so I couldn't say I'm going down the right path with those.
Everything else seems standard.
If not the URL routing, what exactly does not work?
The URL for the child post is
http://example.com/features/yosemite/half-dome/, not the desired
http://example.com/parks/yosemite/half-dome/. Both links lead to a 404
error.
More information about the wp-hackers
mailing list