我已经在Wordpress中注册了自定义分类法,但是由于引入了Gutenberg,所以我无法弄清为什么它没有在标准的Wordpress帖子中显示。我的意思是,添加或编辑帖子时它不会显示在文档侧栏中。“类别”和“标签”也是如此,它们显然是标准分类法。我已确保'show_in_rest'=> true存在于分类法注册中,但没有任何区别。好像它们正在部分注册,因为它们显示在左侧主菜单的“帖子”下,这表明可能与古腾堡有关?有任何想法吗?// Register taxonomyadd_action( 'init', 'register_taxonomy_articles_element' );function register_taxonomy_articles_element() { $labels = array( 'name' => _x( 'Elements', 'articles_element' ), 'singular_name' => _x( 'Element', 'articles_element' ), 'search_items' => _x( 'Search Elements', 'articles_element' ), 'popular_items' => _x( 'Popular Elements', 'articles_element' ), 'all_items' => _x( 'All Elements', 'articles_element' ), 'parent_item' => _x( 'Parent Element', 'articles_element' ), 'parent_item_colon' => _x( 'Parent Element:', 'articles_element' ), 'edit_item' => _x( 'Edit Element', 'articles_element' ), 'update_item' => _x( 'Update Element', 'articles_element' ), 'add_new_item' => _x( 'Add New Element', 'articles_element' ), 'not_found' => _x( 'No Elements found', 'articles_element' ), 'new_item_element' => _x( 'New Element', 'articles_element' ), 'separate_items_with_commas' => _x( 'Separate Elements with commas', 'articles_element' ), 'add_or_remove_items' => _x( 'Add or remove elements', 'articles_element' ), 'choose_from_most_used' => _x( 'Choose from the most used elements', 'articles_element' ), 'menu_name' => _x( 'Elements', 'articles_element' ) ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_in_nav_menus' => true, 'show_in_rest' => true, 'show_ui' => true, 'show_tagcloud' => true, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true ); register_taxonomy( 'element', array('post'), $args );}
2 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
由于Gutenberg基于REST API进行工作,因此您需要为任何自定义帖子类型和分类标准打开对REST API的支持。你需要额外的键添加show_in_rest = true到您的$args阵列。您的完整代码应如下所示:
$args = array(
'labels' => $labels,
'public' => true,
'show_in_rest' => true, // add support for Gutenberg editor
'publicly_queryable' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'rewrite' => true,
'query_var' => true
);
- 2 回答
- 0 关注
- 151 浏览
添加回答
举报
0/150
提交
取消