[wp-trac] [WordPress Trac] #51666: Cannot unselect terms for a taxonomy with a default_term

WordPress Trac noreply at wordpress.org
Thu Oct 29 17:54:51 UTC 2020


#51666: Cannot unselect terms for a taxonomy with a default_term
----------------------------+-----------------------------
 Reporter:  helgatheviking  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 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
 [[Image(https://p119.p3.n0.cdn.getcloudapp.com/items/NQu15w0W/Image%202020-10-29%20at%2011.44.17%20AM.png?v=3163339b0d409341ca55c50a8c06282d)]]

 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.

 {{{#!php
 /**
  * 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' );

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51666>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list