0

I am trying to rewrite a custom taxonomy url to include the CTP slug to which the taxonomy is assigned to. For example:

https://www.example.com/motors/taxonomy-slug/
Where motors is the CPT slug and taxonomy-slug is taxonomy slug.

Here is my code that I am using to register the taxonomy.

function nfinity_motors_cat() {

    $labels = array(
        'name'                       => _x( 'Motors Categories', 'Taxonomy General Name', 'nfinity' ),
        'singular_name'              => _x( 'Motors Category', 'Taxonomy Singular Name', 'nfinity' ),
        'menu_name'                  => __( 'Motors Category', 'nfinity' ),
        'all_items'                  => __( 'All Items', 'nfinity' ),
        'parent_item'                => __( 'Parent Item', 'nfinity' ),
        'parent_item_colon'          => __( 'Parent Item:', 'nfinity' ),
        'new_item_name'              => __( 'New Item Name', 'nfinity' ),
        'add_new_item'               => __( 'Add New Item', 'nfinity' ),
        'edit_item'                  => __( 'Edit Item', 'nfinity' ),
        'update_item'                => __( 'Update Item', 'nfinity' ),
        'view_item'                  => __( 'View Item', 'nfinity' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'nfinity' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'nfinity' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'nfinity' ),
        'popular_items'              => __( 'Popular Items', 'nfinity' ),
        'search_items'               => __( 'Search Items', 'nfinity' ),
        'not_found'                  => __( 'Not Found', 'nfinity' ),
        'no_terms'                   => __( 'No items', 'nfinity' ),
        'items_list'                 => __( 'Items list', 'nfinity' ),
        'items_list_navigation'      => __( 'Items list navigation', 'nfinity' ),
    );
    $rewrite = array(
        'slug'                       => 'motors',
        'with_front'                 => false,
        'hierarchical'               => false,
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
        'rewrite'                    => $rewrite,
    );
    register_taxonomy( 'motorscat', array( 'motors' ), $args );

}
add_action( 'init', 'nfinity_motors_cat', 0 );  

That gives me a 404 error. I have tried setting with_front to true as well as flashed the permalinks. I have searched for several solutions here on SE as well as Google, but same results everytime.

Please help.

  • The easiest way is to add the CPT slug to the 'rewrite' parameter in register_taxonomy(). Look at similar questions like this or this – nmr Jul 15 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.