I have a post type /city/ .. lets say i create a city called toronto with the slug toronto-canada.
now i have /city/toronto-canada/
is there a way i can have more paths for each post in the custom post type added dynamically?
for example when i make the toronto post there should be a path that is: /city/toronto-canada/stores and /city/toronto-canada/things-to-do
pretty much just a defined url for each post /city/toronto-canada/whatever
// City Post Type & Taxonomy
function create_city_category_hierarchical_taxonomy() {
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Categories' ),
);
register_taxonomy('city_category',null, array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'cities'),
));
}
function city_post_type() {
$labels = array(
'name' => _x( 'Cities', 'post type general name' ),
'singular_name' => _x( 'City', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New City' ),
'edit_item' => __( 'Edit City' ),
'new_item' => __( 'New City' ),
'all_items' => __( 'All Cities' ),
'view_item' => __( 'View Cities' ),
'search_items' => __( 'Search Cities' ),
'not_found' => __( 'No City found' ),
'not_found_in_trash' => __( 'No Cities found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Cities'
);
$args = array(
'labels' => $labels,
'description' => 'Holds xxx Cities',
'public' => true,
'menu_position' => 99999,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes','comments' ),
'taxonomies' => array('city_category'),
'has_archive' => true,
'has_parent' => true,
'menu_icon' => 'dashicons-building',
'hierarchical' => true,
'rewrite' => array('slug' => 'city'),
);
register_post_type( 'city', $args );
flush_rewrite_rules();
}
add_action( 'init', 'create_city_category_hierarchical_taxonomy', 0 );
add_action( 'init', 'city_post_type' );
Thanks!.