Gutenberg: Custom taxonomy terms not showing as list in post edit view

Created on 12 Dec 2018  Â·  4Comments  Â·  Source: WordPress/gutenberg

Maybe it is the wanted behavior, but: I have created a Custom Taxonomy for a Custom Post Type. When editing a post of this CPT, I see the meta box of the Custom Taxonomy with a field to add new or select existing terms. But there is no list of all existing terms, like it is the case for the normal blog categories.

This is what I get:

custom-taxonomy-question

While searching if that is the right behavior, I saw a screenshot from WooCommerce in another issue (https://github.com/WordPress/gutenberg/issues/3369#issuecomment-342550484) where such a list is present, so I’m wondering – how can I get such a list of all existing terms for my Custom Taxonomy? :)

This is the code for registering the Custom Taxonomy:

$product_cats_args = array(
    'labels'                     => $product_cats_labels,
    'hierarchical'               => false,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => false,
    'show_in_rest'               => true,
    'show_tagcloud'              => false,
);
register_taxonomy( 'product_cats', array( 'collection' ), $product_cats_args );

Thanks in advance!

[Feature] Document Settings [Type] Help Request

Most helpful comment

$product_cats_args = array(
'labels' => $product_cats_labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_tagcloud' => false,
);
register_taxonomy( 'product_cats', array( 'collection' ), $product_cats_args );

The show_in_rest' => true does the trick here. It seems like, for some reason, wordpress fetches the posts taxonomies via a REST request instead of rendering them with php. If show_in_rest is set to false, the REST callback ignores that taxonomy

All 4 comments

Isn't this just a difference between hierarchical and non-hierarchical taxonomies?

Just like in the Classic Editor, hierarchical taxonomies like categories get checkboxes, flat taxonomies like post tags get a free-form text field.

Thanks a lot @swissspidy, that was the problem, changing hierarchical to true fixes it :)

$product_cats_args = array(
'labels' => $product_cats_labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_tagcloud' => false,
);
register_taxonomy( 'product_cats', array( 'collection' ), $product_cats_args );

$product_cats_args = array(
'labels' => $product_cats_labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_tagcloud' => false,
);
register_taxonomy( 'product_cats', array( 'collection' ), $product_cats_args );

The show_in_rest' => true does the trick here. It seems like, for some reason, wordpress fetches the posts taxonomies via a REST request instead of rendering them with php. If show_in_rest is set to false, the REST callback ignores that taxonomy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maddisondesigns picture maddisondesigns  Â·  3Comments

franz-josef-kaiser picture franz-josef-kaiser  Â·  3Comments

nylen picture nylen  Â·  3Comments

moorscode picture moorscode  Â·  3Comments

aaronjorbin picture aaronjorbin  Â·  3Comments