Make WordPress Core


Ignore:
Timestamp:
07/07/2020 12:53:41 AM (4 years ago)
Author:
whyisjake
Message:

Taxonomy: Add support for default terms for custom taxonomies.

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

Fixes #43517.

Props enrico.sorcinelli, SergeyBiryukov, desrosj, davidbaumwald, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r48314 r48356  
    40344034    }
    40354035
     4036    // Add default term for all associated custom taxonomies.
     4037    if ( 'auto-draft' !== $post_status ) {
     4038        foreach ( get_object_taxonomies( $post_type, 'object' ) as $taxonomy => $tax_object ) {
     4039            if ( ! empty( $tax_object->default_term ) && ( empty( $postarr['tax_input'] ) || ! isset( $postarr['tax_input'][ $taxonomy ] ) ) ) {
     4040                $postarr['tax_input'][ $taxonomy ] = array();
     4041            }
     4042        }
     4043    }
     4044
    40364045    // New-style support for all custom taxonomies.
    40374046    if ( ! empty( $postarr['tax_input'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.