php - 自定义分类法未在 Post Gutenberg 编辑器中显示

标签 php wordpress custom-taxonomy wordpress-gutenberg

我已经在 Wordpress 中注册了一个自定义分类法,但我无法弄清楚为什么它没有显示在标准的 Wordpress 帖子中,因为已经引入了 Gutenberg。我的意思是,在添加或编辑帖子时,它不会显示在文档侧栏中。 'Categories' 和 'Tags' 也是如此,它们显然是标准分类法。

我已经确保 'show_in_rest' => true 存在是分类法注册,但它没有任何区别。

似乎他们正在部分注册,因为它们显示在主左侧菜单的“帖子”下,这表明它可能与古腾堡有关?

有任何想法吗?

// Register taxonomy
add_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 );
}

最佳答案

如果有人在显示分类法或古腾堡编辑器时仍有问题,请添加 'show_in_rest' => true,自定义帖子类型和分类 论据。

关于php - 自定义分类法未在 Post Gutenberg 编辑器中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55870989/

相关文章:

php - 如何从PHP中的csv文件中提取数据

php - SQL参数警告

javascript - jquery ajax - 为什么 .load() 无法加载自身页面?

css - 我如何居中我的菜单

php - 更改购物车列的顺序而不覆盖 Woocommerce 中的模板文件

php - 从 WP_Query 中的当前产品类别术语 ID 获取所有 Woocommerce 产品

php - 使用 PHP 打开或创建文件时权限被拒绝

javascript - 如何使li元素悬停动态

php - 在 Woocommerce 管理产品列表中使特色列可排序

php - Wordpress:修改内容功能