Make WordPress Core

Opened 4 months ago

Last modified 3 months ago

#43517 reviewing enhancement

Adding support of default category term for custom taxonomies

Reported by: enrico.sorcinelli Owned by: SergeyBiryukov
Milestone: 5.0 Priority: normal
Severity: normal Version: trunk
Component: Taxonomy Keywords: has-patch has-unit-tests
Focuses: Cc:


This patch aims to add the support for default category term in custom taxonomies in the same way that is done for built-in taxonomies.

The new default_term argument is added to register_taxonomy() allowing to define the default term name and optionally slug and description. For example:

register_taxonomy( 'custom-tax', 'my-cpt', array(
   'default_term' => array( 'name' => 'My default category', 'slug' => 'default-category' ),

This way, by inserting a new my-cpt object without setting any custom-tax terms, the default term 'My default category' will be used for that taxonomy.

The default_taxonomy_{$axonomy} value is used as option_name in order to save default terms id in wp_options.

PS: Apparently, I haven't found any related ticket other than this old one.

Attachments (1)

43517.patch (6.9 KB) - added by enrico.sorcinelli 4 months ago.

Download all attachments as: .zip

Change History (7)

#1 @mukesh27
4 months ago

  • Keywords has-patch added

#2 @enrico.sorcinelli
4 months ago

  • Keywords has-unit-tests added

This ticket was mentioned in Slack in #core by enrico.sorcinelli. View the logs.

3 months ago

#4 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.0

#5 @SergeyBiryukov
3 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.