为什么创建帖子时不显示自定义纳税申报单?

时间:2019-03-17 作者:Jamal Ahmad

我已经创建了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 );
}
请参见图片:

enter image description here enter image description hereenter image description here

1 个回复
最合适的回答,由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
);

相关推荐

Dropdown menu for categories

当我使用下面的代码时<?php wp_nav_menu( array(\'menu\' => \'categories\' )); ?> 我可以创建一个新的菜单来列出我创建的wordpress中的所有类别。我用它在页面中间列出所有类别。我现在的问题是:有没有一种简单的方法可以为存在的每个子类别创建下拉菜单?那么,当我点击一个特定的类别时,它的子类别会显示出来吗?