0

I have 2 taxonomies ( genre and artist ) and Custom Post Type ( Lyric )

the url structure i want to get is

CPT: /lyrics/ - archive page for CPT Artist: /lyrics/artist/ & /lyrics/artist/song-name/ Genre: /lyrics/genre

i've made CPT and Taxonomies using CPT plugin url is good but on one of taxonomies it's giving me 404 error for page

CPT:

    $args = array(
        "label" => __( "Lyrics", "sage" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "delete_with_user" => false,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "has_archive" => "lyrics",
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "rewrite" => array( "slug" => "lyrics/%artis%",
        "with_front" => true ),
        "query_var" => true,
        "supports" => array( "title", "editor", "thumbnail" ),
        "taxonomies" => array( "genre", "artis" ),
    );

Genre TAX:

 $args = array(
        "label" => __( "Genre", "sage" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => array( 'slug' => 'lyrics', 'with_front' => true, ),
        "show_admin_column" => true,
        "show_in_rest" => true,
        "rest_base" => "genre",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
    );

Artist TAX:

 $args = array(
        "label" => __( "Artist", "sage" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => array( 'slug' => 'lyrics', 'with_front' => true,  'hierarchical' => true, ),
        "show_admin_column" => true,
        "show_in_rest" => true,
        "rest_base" => "artist",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
    );
0

You are specifying the same slug of lyrics for both your custom taxonomies. WordPress by default cannot share the same slugs for two taxonomies due to WordPress' rewrite API. Which caters for the default nature of posts, archives, taxonomies, slugs and the WordPress template hierarchy.

To prevent your 404 errors you can change your artists array to a unique slug like so:

$args = array(
        "label" => __( "Artist", "sage" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => array( 'slug' => 'artists', 'with_front' => true,  'hierarchical' => true, ),
        "show_admin_column" => true,
        "show_in_rest" => true,
        "rest_base" => "artist",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
    );

Ensuring you flush your rewrite rules after doing so

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.