admin管理员组文章数量:1122846
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,
);
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,
);
Share
Improve this question
asked Apr 11, 2019 at 20:18
DzodzosDzodzos
1
1 Answer
Reset to default 0You 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
本文标签: Rewriting url for multiple Taxonomies and Custom Post Type
版权声明:本文标题:Rewriting url for multiple Taxonomies and Custom Post Type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296112a1929716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论