I am building a directory website which has various Custom post Types like Tours, Food, etc. The client would like to see landing Pages for each of the categories which can be edited manually (think archive page as a page template).
There is one taxonomy that needs to be assigned to each of the CPT's which is location. The location consists of a state term and its city child. E.g.:
Custom Taxonomy "Location":
-New South Wales
--Sydney
What I want to achieve is the following structure:
domain.com/food
A landing page create via a page with a page template
domain.com/food/New-South-Wales
A landing page create via a page with a page template. This is created with the food page as a parent
domain.com/food/New-South-Wales/Sydney
A landing page create via a page with a page template. This is created as a grandchild page with the food page as a grandparent and the News South Wales page as a parent
domain.com/food/New-South-Wales/Sydney/RestaurantX
This is the custom post type food single page, utilizing the location taxonomy to create the url structure.
At the moment I have the taxonomy and the CTPs setup without archive and using the CPT Permalinks plugin I am able to achieve all of the functionality, except of
domain.com/food/New-South-Wales/Sydney
which gives me a Page not found error.
Ideally I'd like to drop the CPT Permalinks plugin and create the structure by myself. Can anyone help me with this?
Thanks, Daniel
CPT Code
add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_cpts() {
$labels = array(
"name" => "Foods",
"singular_name" => "Food",
);
$args = array(
"labels" => $labels,
"description" => "",
"public" => true,
"show_ui" => true,
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "food", "with_front" => false ),
"query_var" => true,
"supports" => array( "title", "editor", "excerpt", "thumbnail" ), );
register_post_type( "food", $args );
$labels = array(
"name" => "Bus Tours",
"singular_name" => "Bus Tour",
);
$args = array(
"labels" => $labels,
"description" => "",
"public" => true,
"show_ui" => true,
"has_archive" => true,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "bus-tours", "with_front" => false ),
"query_var" => true,
"supports" => array( "title", "editor", "excerpt", "thumbnail" ), );
register_post_type( "bus-tours", $args );
// End of cptui_register_my_cpts()
}
Taxonomy Code:
add_action( 'init', 'cptui_register_my_taxes' );
function cptui_register_my_taxes() {
$labels = array(
"name" => "location",
"label" => "Locations",
);
$args = array(
"labels" => $labels,
"hierarchical" => true,
"label" => "Locations",
"show_ui" => true,
"query_var" => false,
"rewrite" => array( 'slug' => 'location', 'with_front' => false 'hierarchical' => true ),
"show_admin_column" => false,
);
register_taxonomy( "location", array( "food", "bus-tours" ), $args );
// End cptui_register_my_taxes
}