如何使自定义分类在发布后区域可选?

时间:2019-01-03 作者:rafaelfndev

我注册了一个新的分类法:

function all_about() {
    register_taxonomy( \'all_about\', 
        array(\'post\'), /* if you change the name of register_post_type( \'custom_type\', then you have to change this */
        array(
            \'hierarchical\' => false,    /* if this is false, it acts like tags */                
            \'labels\' => array(
                \'name\' => \'Categorization\', /* name of the custom taxonomy */
                \'singular_name\' => \'Name\', /* single taxonomy name */
                \'search_items\' => \' Search\', /* search title for taxomony */
                \'all_items\' => \'All items\', /* all title for taxonomies */
                \'parent_item\' => \'Parent item\', /* parent title for taxonomy */
                \'parent_item_colon\' => \'Parent item colon:\', /* parent taxonomy title */
                \'edit_item\' => \'Edit\', /* edit custom taxonomy title */
                \'update_item\' => \'Update\', /* update title for taxonomy */
                \'add_new_item\' => \'Add new\', /* add new title for taxonomy */
                \'new_item_name\' => \'New title\' /* name title for taxonomy */
            ),
            \'show_ui\' => true,
            \'query_var\' => true,
            \'rewrite\' => array( \'slug\' => \'all-about\', \'with_front\' => false ),
            \'show_in_nav_menus\' => true,
            \'show_tagcloud\' => true,
            \'show_in_quick_edit\' => true,
        )
    );
}
add_action( \'init\', \'all_about\' );
正常工作:

enter image description here

现在,我需要在这里选择这个新的分类法,就像我可以选择标记一样:

enter image description here

我该怎么做?

1 个回复
最合适的回答,由SO网友:Howdy_McGee 整理而成

它不能自动显示的原因是它需要启用REST才能显示。默认情况下,show_in_rest 注册分类法和帖子类型时设置为false。当前有一个Trac Ticket #42785 打开以更改此默认功能。

因此,简而言之,在使用块编辑器注册分类法时,您需要明确表示:\'show_in_rest\' => true

function all_about() {
    register_taxonomy( \'all_about\', 
        array(\'post\'), /* if you change the name of register_post_type( \'custom_type\', then you have to change this */
        array(
            \'hierarchical\' => false,    /* if this is false, it acts like tags */                
            \'labels\' => array(
                \'name\' => \'Categorization\', /* name of the custom taxonomy */
                \'singular_name\' => \'Name\', /* single taxonomy name */
                \'search_items\' => \' Search\', /* search title for taxomony */
                \'all_items\' => \'All items\', /* all title for taxonomies */
                \'parent_item\' => \'Parent item\', /* parent title for taxonomy */
                \'parent_item_colon\' => \'Parent item colon:\', /* parent taxonomy title */
                \'edit_item\' => \'Edit\', /* edit custom taxonomy title */
                \'update_item\' => \'Update\', /* update title for taxonomy */
                \'add_new_item\' => \'Add new\', /* add new title for taxonomy */
                \'new_item_name\' => \'New title\' /* name title for taxonomy */
            ),
            \'show_ui\' => true,
            \'query_var\' => true,
            \'rewrite\' => array( \'slug\' => \'all-about\', \'with_front\' => false ),
            \'show_in_nav_menus\' => true,
            \'show_tagcloud\' => true,
            \'show_in_quick_edit\' => true,
            \'show_in_rest\' => true,
        )
    );
}
add_action( \'init\', \'all_about\' );

相关推荐

404 - Taxonomy Archive Page

我正在创建一个Wordpress自定义帖子类型,包括一个分类法,在安装之后,所有的永久链接都被刷新了,但是分类法归档页面不断给我404。CPT归档页面工作得非常好。要创建的代码:add_action( \'init\', \'register_cpt_post_type\' ); function register_cpt_post_type() { register_post_type( \'offers\', array(