WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.23k stars 4.08k forks source link

Random disply of custom taxonomies in Gutenberg #9153

Closed chezmat closed 5 years ago

chezmat commented 6 years ago

Describe the bug some Custom taxonomy set to "show_in_rest=>true", but not displayed into gutenberg. But some are displayed correctly into gutenberg. Custom taxonomies where all created from functions.php. To Reproduce Steps to reproduce the behavior:

  1. check here : http://geekroniques.fr/wp-json/wp/v2/taxonomies/chaines, the taxonomy "chaines" is displayed on rest
  2. open a custom post using it, and check that there is no "chaines" displayed (but ti's display if you disable gutenberg..

Expected behavior The "chaines" taxonomy should be displayed into gutenbberg editor.

Screenshots taxonomies acteurs, réalisateurs, createurs are displayed. But chaines and two others are missing : gutenberg

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

danielbachhuber commented 5 years ago

Hi @chezmat,

Can you share a code snippet to help reproduce the issue?

chezmat commented 5 years ago

Hi Daniel,

Here is a part of my functions.php file where i declare some of my custom taxonomies :

/* 7 Déclaration des custom Taxonomy */
add_action( 'init', 'custom_taxonomy', 0 );
function custom_taxonomy() {
/* 7.1 Custom Taxonomy Acteurs (acteurs) */ 
    $labels = array(
        'name'                       => _x( 'Acteurs', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'acteur', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Acteurs', 'text_domain' ),
        'all_items'                  => __( 'Tous les acteurs', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilises', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
        );
    register_taxonomy( 'acteurs', array( 'critiques-series', 'critiques-films','critiques-videos' ), $args );
/* 7.2 Custom Taxonomy Réalisateurs (realisateurs) */
    $labels = array(
        'name'                       => _x( 'Réalisateur', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Realisateur', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Réalisateurs', 'text_domain' ),
        'all_items'                  => __( 'Tous les réalisateurs', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
    );
    register_taxonomy( 'realisateurs', array( 'critiques-series', 'critiques-films','critiques-animes','critiques-videos' ), $args );

/* 7.3 Custom Taxonomy Dessinateurs (Dessinateurs) */
    $labels = array(
        'name'                       => _x( 'Dessinateurs', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Dessinateur', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Dessinateurs', 'text_domain' ),
        'all_items'                  => __( 'Tous les Dessinateurs', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
    );
    register_taxonomy( 'dessinateurs', array( 'critiques-bd'), $args );
/* 7.4 Custom Taxonomy Scénaristes (scenaristes) */
    $labels = array(
        'name'                       => _x( 'Scénariste', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Scénariste', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Scénaristes', 'text_domain' ),
        'all_items'                  => __( 'Tous les Scénaristes', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
    );
    register_taxonomy( 'scenaristes', array( 'critiques-bd'), $args );
/* 7.5 Custom Taxonomy compositeurs (compositeurs) */
    $labels = array(
        'name'                       => _x( 'Compositeur', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Compositeur', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Compositeurs', 'text_domain' ),
        'all_items'                  => __( 'Tous les Compositeurs', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
    );
register_taxonomy( 'compositeurs', array( 'critiques-musique' ), $args );
/* 7.6 Custom Taxonomy Créateurs (createurs) */
    $labels = array(
        'name'                       => _x( 'Créateur', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Créateur', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Créateurs', 'text_domain' ),
        'all_items'                  => __( 'Tous les créateurs', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
    );
    register_taxonomy( 'createurs', array( 'critiques-series'), $args );
/* 7.7 Custom Taxonomy Chaines de diffusion (chaines) */
    $labels = array(
        'name'                       => _x( 'Chaîne', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Chaine', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Chaines', 'text_domain' ),
        'all_items'                  => __( 'Tous les chaînes', 'text_domain' ),
        'new_item_name'              => __( 'Nouvelle chaîne', 'text_domain' ),
        'add_new_item'               => __( 'Ajouter une chaîne', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisées', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
        );
    register_taxonomy( 'chaines', array( 'critiques-series', 'critiques-films','critiques-animes' ), $args );
/* 7.8 Custom Taxonomy Genres (genres) */
    $labels = array(
        'name'                       => _x( 'Genre', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Genre', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Genres', 'text_domain' ),
        'all_items'                  => __( 'Tous les genres', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => false,
    );
    register_taxonomy( 'genres', array( 'critiques-series', 'critiques-films','critiques-animes', 'critiques-livres', 'critiques-bd' ), $args );
/* 7.9 Custom Taxonomy Genre musicaux (genres-musicaux) */
    $labels = array(
        'name'                       => _x( 'Genres Musicaux ', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Genre', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Genres', 'text_domain' ),
        'all_items'                  => __( 'Tous les genres', 'text_domain' ),
        'new_item_name'              => __( 'Nouveau', 'text_domain' ),
        'add_new_item'               => __( 'Nouveau', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisés', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
    );
    register_taxonomy( 'genres-musicaux', array( 'critiques-musique' ), $args );
danielbachhuber commented 5 years ago

Hi @chezmat,

Thanks for the code snippet. I tried reproducing locally by registering the custom taxonomy to post and acme_product:

add_action( 'init', function() {
    $labels = array(
        'name'                       => _x( 'Chaîne', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Chaine', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Chaines', 'text_domain' ),
        'all_items'                  => __( 'Tous les chaînes', 'text_domain' ),
        'new_item_name'              => __( 'Nouvelle chaîne', 'text_domain' ),
        'add_new_item'               => __( 'Ajouter une chaîne', 'text_domain' ),
        'edit_item'                  => __( 'Modifier', 'text_domain' ),
        'update_item'                => __( 'Mettre à jour', 'text_domain' ),
        'view_item'                  => __( 'voir', 'text_domain' ),
        'separate_items_with_commas' => __( 'Ajouter des éléments séparés par une virgule', 'text_domain' ),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer des éléments', 'text_domain' ),
        'choose_from_most_used'      => __( 'Les plus utilisées', 'text_domain' ),
        'popular_items'              => __( 'Populaire', 'text_domain' ),
        'search_items'               => __( 'Rechercher', 'text_domain' ),
        'not_found'                  => __( 'Pas trouvé', 'text_domain' ),
        'items_list'                 => __( 'Items list', 'text_domain' ),
        'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'show_in_rest'               => true,
        );
    register_taxonomy( 'chaines', array( 'post', 'acme_product' ), $args );
} );

The custom taxonomy appears correctly for me:

image

Some follow up questions:

chezmat commented 5 years ago

I am a beginner into coding.. :-) What should i do for priority, change it or remove it? Where can i run your code (i told you, i am a beginner). yes, there is another custom code into my functions.php.

danielbachhuber commented 5 years ago

I am a beginner into coding.. :-)

No worries!

What should i do for priority, change it or remove it?

Can you try changing it to 11? We'd like to make sure the taxonomies are registered after the post types are.

Where can i run your code (i told you, i am a beginner).

When I mentioned "console", I was referring to the Chrome Dev Tools Console. You can learn more about it here: https://developers.google.com/web/tools/chrome-devtools/console/

Essentially, the console lets you run arbitrary JavaScript in the scope of the Gutenberg editor. wp.data.select('core').getTaxonomies(); is the call Gutenberg makes to get the taxonomies to display. If all taxonomies are returned as expected, then the problem lies in the rendering of the component. If the taxonomies aren't all included, then Gutenberg is unable to fetch the taxonomy from the REST API for some reason.

chezmat commented 5 years ago

I change priority to 11, no changes (i already "play' with that). I launched the console and try your code, but i get an error message :

Uncaught TypeError: Cannot read property 'select' of undefined at :1:9

danielbachhuber commented 5 years ago

@chezmat Were you able to track this down? I don't have any more ideas on debugging, unfortunately.

chezmat commented 5 years ago

Nope, still having error message with the request : image

danielbachhuber commented 5 years ago

Ok. If you're able to progress further and find a specific bug within Gutenberg, please re-open the issue and we'll get it fixed.

chezmat commented 5 years ago

no solution, but topic close? Nice.. 👎