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:
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!
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
Most helpful comment
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. Ifshow_in_rest
is set tofalse
, the REST callback ignores that taxonomy