1

I created a custom taxonomy using the following code. Everything works almost perfectly, this one is created. It is available in the admin side menu, as well as in the quick edition on the article listing page. However, I don't have it in the "edit post" admin page (As for categories and tags):

add_action( 'init', 'create_chapitres_taxo', 0 );
  function create_chapitres_taxo() {
    $labels = array(
      'name' => _x( 'Chapitres', 'taxonomy general name' ),
      'singular_name' => _x( 'Chapitre', 'taxonomy singular name' ),
      'search_items' =>  __( 'Recherche un chapitre' ),
      'popular_items' => __( 'Capitres populaires' ),
      'all_items' => __( 'Toutes les catégories' ),
      'parent_item' => null,
      'parent_item_colon' => null,
      'edit_item' => __( 'Editer la chapitre' ),
      'update_item' => __( 'Editer la chapitre' ),
      'add_new_item' => __( 'Ajouter un chapitre' ),
      'new_item_name' => __( 'Ajouter un chapitre' ),
      'separate_items_with_commas' => __( 'Séparer les chapitres avec une virgule' ),
      'add_or_remove_items' => __( 'Ajouter ou retirer un chapitre' ),
      'choose_from_most_used' => __( 'Choisir le chapitre' ),
      'menu_name' => __( 'Chapitres' ),
    );
    register_taxonomy('chapitre','post',array(
      'hierarchical' => false,
      'labels' => $labels,
      'show_ui' => true,
      'show_admin_column' => true,
      'update_count_callback' => '_update_post_term_count',
      'query_var' => true,
      'rewrite' => array( 'slug' => 'chapitres' ),
    ));
  }

enter image description here

but

enter image description here

What can I try to resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

2

You need to add : 'show_in_rest' => true in your arguments for it to be displayed in Gutemberg interface.

So it would become:

  register_taxonomy('chapitre','post',array(
  'hierarchical' => false,
  'labels' => $labels,
  'show_in_rest' => true //add this
  'show_ui' => true,
  'show_admin_column' => true,
  'update_count_callback' => '_update_post_term_count',
  'query_var' => true,
  'rewrite' => array( 'slug' => 'chapitres' ),
));

Note: the same parameter must be used when declaring a custom post type, if you need the Gutemberg block builder interface, and not the classic wysiwyg (on the post edit page).

Mtxz
  • 3,749
  • 15
  • 29
  • Thank you very much I simply forgot this parameter ! ... Is this new from guttenberg? – Vincent Rocher May 17 '20 at 18:49
  • It is yes, so the taxonomy is also available in the WP REST API. Please mark this as the answer if all ok :) Thanks and good luck – Mtxz May 17 '20 at 19:09