Posts, Post Types: Check if taxonomy is set for the tax_input parameter of wp_insert_post().

This avoids a PHP notice when creating a post with multiple taxonomies both having a default term.

Props yakimun, szaqal21, hareesh-pillai, audrasjb.
Fixes #51320.

git-svn-id: https://develop.svn.wordpress.org/trunk@49328 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-10-27 16:40:35 +00:00
parent 986becfd4d
commit fce8f2bf4d
2 changed files with 28 additions and 6 deletions

View File

@@ -4091,7 +4091,7 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true )
if ( ! empty( $tax_object->default_term ) ) {
// Filter out empty terms.
if ( isset( $postarr['tax_input'] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
if ( isset( $postarr['tax_input'][ $taxonomy ] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
$postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] );
}