我已经创建了taxomony,显示在Post选项卡的wordpress菜单栏中。但当我创建新帖子或编辑帖子时,它不会显示类别。有谁能帮我找出我错的地方吗。
Functions.php
add_action( \'init\', \'register_taxonomy_Emerates_State\' );
function register_taxonomy_Emerates_State() {
$labels = array(
\'name\' => _x( \'Emerates_State\', \'State\' ),
\'singular_name\' => _x( \'Emerates_State\', \'State\' ),
\'search_items\' => _x( \'Search Emerates_State\', \'State\' ),
\'popular_items\' => _x( \'Popular Emerates_State\', \'State\' ),
\'all_items\' => _x( \'All Emerates_State\', \'State\' ),
\'parent_item\' => _x( \'Parent Emerates_State\', \'State\' ),
\'parent_item_colon\' => _x( \'Parent Emerates_State:\', \'State\' ),
\'edit_item\' => _x( \'Edit Emerates_State\', \'State\' ),
\'update_item\' => _x( \'Update Emerates_State\', \'State\' ),
\'add_new_item\' => _x( \'Add New Emerates_State\', \'State\' ),
\'new_item_name\' => _x( \'New Emerates_State\', \'State\' ),
\'separate_items_with_commas\' => _x( \'Separate Emerates_State with commas\', \'State\' ),
\'add_or_remove_items\' => _x( \'Add or remove Emerates_State\', \'State\' ),
\'choose_from_most_used\' => _x( \'Choose from the most used Emerates_State\', \'State\' ),
\'menu_name\' => _x( \'Emerates_State\', \'State\' ),
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => false,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'with_front\'=> true,
\'query_var\' => true,
\'has_archive\' => true,
\'rewrite\' => array( \'slug\' => \'state\' )
);
register_taxonomy( \'State\', array(\'post\'), $args );
}
请参见图片:
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
看起来您正在使用新的块编辑器(Gutenberg)。
在这种情况下,您应该知道这个编辑器是基于REST的。因此,如果希望在此编辑器中查看自定义分类法,则必须使其在rest中可见。
您应该设置show_in_rest
参数到true
.
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => false,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'with_front\'=> true,
\'query_var\' => true,
\'has_archive\' => true,
\'rewrite\' => array( \'slug\' => \'state\' ),
\'show_in_rest\' => true
);