WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 5 months 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 https://p119.p3.n0.cdn.getcloudapp.com/items/NQu15w0W/Image%202020-10-29%20at%2011.44.17%20AM.png

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)

#1 @mukesh27
6 months ago

  • Component changed from General to Taxonomy

#2 @helgatheviking
6 months ago

  • Component changed from Taxonomy to General

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:
https://core.trac.wordpress.org/ticket/43516

Version 1, edited 6 months ago by helgatheviking (previous) (next) (diff)

#3 @SergeyBiryukov
5 months ago

  • Component changed from General to Taxonomy
Note: See TracTickets for help on using tickets.