添加新的自定义帖子类型时未显示自定义分类

时间:2019-02-03 作者:Michiel Standaert

我添加了分类法和自定义帖子类型,但由于某种原因,在添加新标记时,我的分类法没有显示出来。我有点期待它会出现,就像在为一篇文章选择一个类别时一样,但事实并非如此。有什么想法吗?

function register_mm_post_types()
{
    register_taxonomy(\'marker_types\', 
        array(\'markers\'), 
        array(
        \'labels\'            => array(
            \'name\'              => __(\'Marker type\', \'moxxie\'),
            \'singular_name\'     => __(\'Marker type\', \'moxxie\'),
            \'search_items\'      => __(\'Search marker types\', \'moxxie\'),
            \'all_items\'         => __(\'All marker types\', \'moxxie\'),
            \'parent_item\'       => __(\'Parent marker type\', \'moxxie\'),
            \'parent_item_colon\' => __(\'Parent marker type:\', \'moxxie\'),
            \'edit_item\'         => __(\'Edit marker type\', \'moxxie\'), 
            \'update_item\'       => __(\'Update marker type\', \'moxxie\'),
            \'add_new_item\'      => __(\'Add new marker type\', \'moxxie\'),
            \'new_item_name\'     => __(\'New marker type name\', \'moxxie\'),
            \'menu_name\'         => __(\'Marker types\', \'moxxie\')
        ),

        \'show_ui\'           => true,
        \'query_var\'         => true,
        \'hierarchical\'      => true,
        \'show_admin_column\' => true,
        \'rewrite\'           => array(\'slug\' => \'marker_types\')
    ));

    register_post_type(\'markers\', 
        array(  \'taxonomies\'            => array(\'marker_types\'),
                \'labels\'                => array(
                    \'name\'                  => __(\'Map markers\', \'moxxie\'),
                    \'singular_name\'         => __(\'Marker\', \'moxxie\'),
                    \'add_new\'               => __(\'Add a new marker\', \'moxxie\'),
                    \'edit_item\'             => __(\'Edit marker\', \'moxxie\'),
                    \'new_item\'              => __(\'New marker\', \'moxxie\'),
                    \'view_item\'             => __(\'View marker\', \'moxxie\'),
                    \'search_items\'          => __(\'Search in maps\', \'moxxie\'),
                    \'not_found\'             => __(\'No markers found\', \'moxxie\'),
                    \'not_found_in_trash\'    => __(\'No markers found in trash\', \'moxxie\')
                ),

                \'has_archive\'           => true,
                \'show_in_rest\'          => true,
                \'hierarchical\'          => true,
                \'public\'                => true,
                \'menu_icon\'             => \'dashicons-location\',
                \'capability_type\'       => \'post\'
    ));
}
add_action(\'init\', \'register_mm_post_types\', 1); 
如您所见,没有显示分类法。它必须出现在右侧栏中,就像帖子中的类别一样。

As you can see, no taxonomy

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

Gutenberg编辑器依赖REST API,因此post类型和分类法都需要show_in_rest 参数设置为true 注册时。你的帖子类型有这个,但你的分类法中没有它。

相关推荐

Custom Taxonomy Category link

我似乎在这里转圈转圈,我认为缺乏词汇或不知道我在寻找什么是造成我问题的原因。我有一个自定义的帖子类型projects 并有一个分类法来反映这一点当尝试在菜单中添加此帖子类型的类别链接时,它会在站点上链接为域。com/类别/自定义\\u类别理想情况下,我希望URL为:域。com/projects/custom\\u cat谁能给我指一下正确的方向吗。非常感谢!Edit:我想我展开了一个问题,创造了另一个问题,我取代了: register_taxonomy( \'category\', \'project\'