How to rewrite custom post type with custom taxonomy urls?

I am working in a WP multisite which runs on a classipress theme and there is a custom post type “ad_listing” and custom taxonomy type “ad_cat“. Now the url is like this

http://www.example.com/ad-category/transport/

I need to rewrite this URL so it looks like

http://www.example.com/new-york-city/transport/

and categories are nested so it can be nth level.

Please help me how to do that with wp rewrite rules.

Thanks in advance.Any help will be greatly appreciated.

1 Answer
1

When you are adding a custom taxonomy you are able to declare a rewrite slug –

$labels = array(
    'name' => _x('Name', 'taxonomy general name'),
    'singular_name' => _x('Singular Name', 'taxonomy singular name'),
    'search_items' =>  __('Search Items'),
    'all_items' => __('All Names'),
    'parent_item' => __('Parent Item'),
    'parent_item_colon' => __( 'Parent Ites:'),
    'edit_item' => __('Edit Item'), 
    'update_item' => __('Update Item'),
    'add_new_item' => __('Add New Item'),
    'new_item_name' => __('New Item Name'),
);

register_taxonomy(
    'ad_category',
    array('post-type1', 'post-type2'),
    array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array('slug' =>'new-york-city')
    )
);

Leave a Comment