For following post type and taxonomy:
/**
* Register restaurant post type
*/
function wpse_287682_register_restaurant_post_type() {
$labels = array(
'name' => __( 'Restaurants' ),
'singular_name' => __( 'Restaurant' ),
'add_new' => __( 'Add new' ),
'add_new_item' => __( 'Add new' ),
'edit_item' => __( 'Edit' ),
'new_item' => __( 'New' ),
'view_item' => __( 'View' ),
'search_items' => __( 'Search' ),
'not_found' => __( 'Not found' ),
'not_found_in_trash' => __( 'Not found Restaurants in trash' ),
'parent_item_colon' => __( 'Parent' ),
'menu_name' => __( 'Restaurants' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'supports' => array( 'title', 'editor' ),
'taxonomies' => array(),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array( 'slug' => 'restaurant' ),
'capability_type' => 'post',
);
register_post_type( 'restaurant', $args );
}
add_action( 'init', 'wpse_287682_register_restaurant_post_type' );
/**
* Register district taxonomy
*/
function wpse_287682_register_district_taxonomy() {
$labels = array(
'name' => __( 'Districts' ),
'singular_name' => __( 'District' ),
'search_items' => __( 'Search Districts' ),
'all_items' => __( 'All Districts' ),
'parent_item' => __( 'Parent District' ),
'parent_item_colon' => __( 'Parent District:' ),
'edit_item' => __( 'Edit District' ),
'update_item' => __( 'Update District' ),
'add_new_item' => __( 'Add New District' ),
'new_item_name' => __( 'New District Name' ),
'menu_name' => __( 'District' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'district' ),
);
register_taxonomy( 'district', array( 'restaurant' ), $args );
}
add_action( 'init', 'wpse_287682_register_district_taxonomy', 0 );
You can add this kind of rewrite rule.
/**
* Add custom rewrite rule for restaurant post type and district taxonomy.
*
* Remember to flush rewrite rules to apply changes.
*/
function wpse_287682_add_restaurant_district_rewrite_rule() {
add_rewrite_rule('restaurant/district/([^/]+)/?$', 'index.php?post_type=restaurant&district=$matches[1]', 'top');
}
add_action('init', 'wpse_287682_add_restaurant_district_rewrite_rule');
Your link for citycenter district will be:
http://example.com/restaurant/district/citycenter/
.
Remember to flush rewrite rules after code update.