自定义分类法元框未显示在 WordPress 管理菜单中

custom taxonomy meta box doesn't show in the WordPress admin menu

我在 WordPress functions.php 文件中创建了一个新的自定义分类法,但是当我想添加新的 post 或编辑一个时,我在管理员的右侧找不到我的自定义分类法元框菜单

我的 functions.php 自定义分类代码:

function create_business_taxonomy() {
 
  $labels = array(
    'name' => _x( 'Businesses', 'taxonomy general name' ),
    'singular_name' => _x( 'Business', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Businesses' ),
    'all_items' => __( 'All Businesses' ),
    'parent_item' => __( 'Parent Business' ),
    'parent_item_colon' => __( 'Parent Business:' ),
    'edit_item' => __( 'Edit Business' ), 
    'update_item' => __( 'Update Business' ),
    'add_new_item' => __( 'Add New Business' ),
    'new_item_name' => __( 'New Business Name' ),
    'menu_name' => __( 'Business' ),
  );    
 
  register_taxonomy('business-type',array('post'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => false,
    'query_var' => true,
    'rewrite' => array( 'business-type' => 'topic' ),
  ));
  
}

add_action( 'init', 'create_business_taxonomy', 0 );

但是我在截图中标记的地方找不到:

我是不是忘记或遗漏了什么?

您需要设置 'show_in_rest' => true。 ((布尔值)(可选)是否在 REST API 中包含分类法。您需要将其设置为 true 才能在 gutenberg metablock 中使用分类法。)。所以你的代码将是这样的:

function create_business_taxonomy() {
 
  $labels = array(
    'name' => _x( 'Businesses', 'taxonomy general name' ),
    'singular_name' => _x( 'Business', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Businesses' ),
    'all_items' => __( 'All Businesses' ),
    'parent_item' => __( 'Parent Business' ),
    'parent_item_colon' => __( 'Parent Business:' ),
    'edit_item' => __( 'Edit Business' ), 
    'update_item' => __( 'Update Business' ),
    'add_new_item' => __( 'Add New Business' ),
    'new_item_name' => __( 'New Business Name' ),
    'menu_name' => __( 'Business' ),
  );    
 
  register_taxonomy('business-type',array('post'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => false,
    'query_var' => true,
    'show_in_rest' => true,
    'rewrite' => array( 'business-type' => 'topic' ),
  ));
  
}

add_action( 'init', 'create_business_taxonomy', 0 );