0
votes

I have created a new custom taxonomy in WordPress functions.php file but when I want to add new post or edit one I cannot found my custom taxonomy meta box in the right side of the admin menu

my functions.php code for custom taxonomy:

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 );

but I can't find in where I marked in the screenshot:

enter image description here

enter image description here

Did I forget or missed something?

1

1 Answers

0
votes

You need to set 'show_in_rest' => true. ( (boolean) (optional) Whether to include the taxonomy in the REST API. You will need to set this to true in order to use the taxonomy in your gutenberg metablock. ). So your code will be like this:

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 );