Posts, Post Types: Prevent categories from being overwritten when updating a post using wp_insert_post().

This prevents existing category relationships being overridden with the default category when none is provided in the post data.

Props markoheijnen, leewillis77, desrosj

Fixes #19954


git-svn-id: https://develop.svn.wordpress.org/trunk@53883 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2022-08-11 19:58:21 +00:00
parent 7bb8dc6269
commit 40c19e45bf
2 changed files with 47 additions and 0 deletions

View File

@@ -4142,6 +4142,8 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true )
if ( ! empty( $postarr['post_category'] ) ) {
// Filter out empty terms.
$post_category = array_filter( $postarr['post_category'] );
} elseif ( $update && ! isset( $postarr['post_category'] ) ) {
$post_category = $post_before->post_category;
}
// Make sure we set a valid category.