Opened 4 years ago
Last modified 4 years ago
#51666 new defect (bug)
Cannot unselect terms for a taxonomy with a default_term
Reported by: | helgatheviking | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
I've created a custom post type and assigned a custom taxonomy. When registering the taxonomy I have defined the new default_term
parameter.
I see the default term I've defined in the taxonomy metabox
If I save a term, and then next time decide to remove that term, it cannot be removed. Whatever term was checked stays checked after save.
Here is a video:
https://share.getcloudapp.com/rRuom70d
Here's my test code for setting up a CPT and a taxonomy.
/**
* Register a custom post type called "book".
*
* @see get_post_type_labels() for label keys.
*/
function kia_codex_book_init() {
$args = array(
'public' => true,
'label' => __( 'Books', 'textdomain' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'kia_codex_book_init' );
/**
* Book Taxonomies
*/
function kia_create_book_taxonomies() {
$args = array(
'hierarchical' => false,
'label' => __( 'Genres', 'textdomain' ),
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
'default_term' => array( 'name' => 'My default genre', 'slug' => 'default-genre' ),
);
register_taxonomy( 'genre', array( 'book' ), $args );
}
add_action( 'init', 'kia_create_book_taxonomies' );
Change History (3)
Note: See
TracTickets for help on using
tickets.
To reproduce:
If you have a new post and save it without making a selection... the default term becomes selected. That's what I'd expect for a "Default".
From there, if you uncheck the default term and check another term and save again.... the other term is selected like normal.
Finally, uncheck the current term and save. I would expect the default term to become selected again. Instead the previous terms stay selected and no change is detected.
I believe this is related to: #43516