[wp-trac] [WordPress Trac] #43517: Adding support of default category term for custom taxonomies

WordPress Trac noreply at wordpress.org
Tue Sep 1 21:39:40 UTC 2020


#43517: Adding support of default category term for custom taxonomies
------------------------------------+------------------------
 Reporter:  enrico.sorcinelli       |       Owner:  whyisjake
     Type:  defect (bug)            |      Status:  closed
 Priority:  normal                  |   Milestone:  5.5
Component:  Taxonomy                |     Version:
 Severity:  normal                  |  Resolution:  fixed
 Keywords:  has-patch has-dev-note  |     Focuses:
------------------------------------+------------------------

Comment (by enrico.sorcinelli):

 Hi @helgatheviking,
 in order to auto-add  the default custom taxonomy term when saving or
 updating post without custom taxonomy terms you have to explicitly define
 `default_term` when registering the custom taxonomy, for example:

 {{{
 #!php
 register_taxonomy(
         'custom-tax',
         'post',
         array(
                 'labels'=> array(
                         'name' => 'Custom tax'
                 ),
                 'hierarchical' => true,
                 'public'       => true,
                 'show_ui'      => true,
                 'show_admin_column' => true,
                 'show_in_nav_menus' => true,
                 'show_in_menu'      => true,
                 'show_in_rest'      => true,
                 'default_term' => array(
                         'name' => 'Default category',
                         'slug' => 'default-category',
                 ),
         )
 );
 }}}

 However note that with block editor this doesn't happen in the same manner
 (for example if you remove all category or custom taxonomy terms, the
 default term will not be auto re-added to the post). See #50648

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43517#comment:42>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list