我注册了一个名为districts的分类法,但当我将districts添加到nav菜单时,nav菜单项无效!以下是注册分类的代码:
function masallah() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
\'name\' => _x( \'Districts\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'District\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Districts\' ),
\'all_items\' => __( \'All Districts\' ),
\'parent_item\' => __( \'Parent Districts\' ),
\'parent_item_colon\' => __( \'Parent District:\' ),
\'edit_item\' => __( \'Edit District\' ),
\'update_item\' => __( \'Update District\' ),
\'add_new_item\' => __( \'Add New District\' ),
\'new_item_name\' => __( \'New Topic District\' ),
\'menu_name\' => __( \'Districts\' ),
);
// Now register the taxonomy
register_taxonomy(\'Districts\',array(\'post\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'show_in_rest\' => true,
\'rewrite\' => true,
\'rewrite\' => array( \'slug\' => \'districts\' ),
\'has_archive\' => true,
));
}
add_action( \'init\', \'masallah\', 0 );
最合适的回答,由SO网友:Tom J Nowell 整理而成
我已经确定了两个问题,第一个是:
\'rewrite\' => true,
\'rewrite\' => array( \'slug\' => \'districts\' ),
可能就是这样:
\'rewrite\' => array( \'slug\' => \'districts\' ),
第二,你得到无效菜单项的原因是
districts
正在用作重写slug,但分类法的内部名称为
Districts
.
更换Districts
具有districts
由于内部名称为我修复了本地问题:
register_taxonomy( \'districts\', array(\'post\'), array(
一般的经验法则是将事物的内部名称保持小写,您可以始终使用用户看到的标签