如何获取此自定义POST类型固定链接结构?%CUSTOM_POST_TYPE%-%TASTIONY%-%TERM-POSTNAME%

时间:2017-04-16 作者:Lee Walpole

请帮忙,我几乎什么都试过了,我完全迷路了!

我非常渴望建立以下permalink结构:

ladsholidayguide。com/custom\\u post/taxonomy/term/postname

例如:ladsholidayguide。com/评论/场馆/俱乐部/流动夜总会

我尝试过使用自定义的Post-Type Permalinks插件,但是这个选项也不起作用

选中此项,自定义分类法的永久链接将为:www.ladsholidayguide。com/post\\u type/taxonomy/term/postname/

出于某种原因

这很好用。ladsholidayguide。com/评论/场馆/伦敦垃圾场高尔夫/

这不是(我得到404)ladsholidayguide。com/评论/场馆/餐厅/imads叙利亚厨房/

似乎术语/子类别打破了它。

下面是使用的代码:如果有人知道如何修复此问题,请告诉我。

/** Custom Post Type Post Type: Reviews: **/

function cptui_register_my_cpts_reviews() {

    $labels = array(
        "name" => __( \'Reviews\', \'\' ),
        "singular_name" => __( \'Review\', \'\' ),
    );

    $args = array(
        "label" => __( \'Reviews\', \'\' ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "show_in_rest" => false,
        "rest_base" => "",
        "has_archive" => true,
        "show_in_menu" => true,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "rewrite" => array( "slug" => "reviews", "with_front" => false ),
        "query_var" => true,
        "supports" => array( "title", "editor", "thumbnail" ),
        "taxonomies" => array( "review" ),
    );

    register_post_type( "reviews", $args );
}

add_action( \'init\', \'cptui_register_my_cpts_reviews\' );


    /** Taxonomy: Review (not reviews due to custom post type name). **/

function cptui_register_my_taxes_review() {

    $labels = array(
        "name" => __( \'Review\', \'\' ),
        "singular_name" => __( \'review\', \'\' ),
    );

    $args = array(
        "label" => __( \'Review\', \'\' ),
        "labels" => $labels,
        "public" => true,
        "hierarchical" => true,
        "label" => "Review",
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => array( \'slug\' => \'review\', \'with_front\' => true,  \'hierarchical\' => true, ),
        "show_admin_column" => false,
        "show_in_rest" => false,
        "rest_base" => "",
        "show_in_quick_edit" => false,
    );
    register_taxonomy( "review", array( "reviews" ), $args );
}

add_action( \'init\', \'cptui_register_my_taxes_review\' );

1 个回复
SO网友:jay_R_champ

相关推荐

显示所有类别而不是分配给特定帖子的类别的GET_TERMS

我的自定义帖子类型中有3篇帖子(\'careers\'). 我注册了自定义分类法(\'career_categories\').我创建了3个职位,其中两个职位属于“全职”,一个职位属于“兼职”。我在循环中使用以下代码:$terms = get_terms( \'career_categories\', array( \'hide_empty\' => true, ) ); $html_out .= \'<td class=\"column-\'. $col++ .\'\"&g