重写多个分类和自定义帖子类型的URL

时间:2019-04-11 作者:Dzodzos

我有2个分类法(流派和艺术家)和自定义帖子类型(歌词)

我想得到的url结构是

CPT:/lyrs/-CPTArtist的存档页:/lyrs/artist/&/歌词/艺术家/歌曲名称/流派:/歌词/流派

我已经使用CPT pluginurl制作了CPT和分类法,这很好,但在其中一个分类法上,它给了我404页的错误

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" ),
    );
类型税:

 $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,
    );
艺人税:

 $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,
    );

1 个回复
SO网友:Craig Pearson

您正在指定相同的段塞lyrics 对于两种自定义分类法。由于WordPress的rewrite API. 它迎合了帖子、归档、分类法、slug和WordPress template hierarchy.

为了防止404错误,您可以将艺术家阵列更改为唯一slug 像这样:

$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,
    );
确保您flush your rewrite rules 这样做之后

相关推荐