diff --git a/src/wp-includes/taxonomy-functions.php b/src/wp-includes/taxonomy-functions.php index 3a3fd2a6cc..22f858da26 100644 --- a/src/wp-includes/taxonomy-functions.php +++ b/src/wp-includes/taxonomy-functions.php @@ -2908,6 +2908,8 @@ function wp_remove_object_terms( $object_id, $terms, $taxonomy ) { do_action( 'delete_term_relationships', $object_id, $tt_ids ); $deleted = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id ) ); + wp_cache_delete( $object_id, $taxonomy . '_relationships' ); + /** * Fires immediately after an object-term relationship is deleted. * diff --git a/tests/phpunit/tests/term/wpRemoveObjectTerms.php b/tests/phpunit/tests/term/wpRemoveObjectTerms.php new file mode 100644 index 0000000000..a49278160c --- /dev/null +++ b/tests/phpunit/tests/term/wpRemoveObjectTerms.php @@ -0,0 +1,24 @@ +post->create(); + $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); + + wp_set_object_terms( $p, $t, 'wptests_tax' ); + + // Pollute the cache. + get_the_terms( $p, 'wptests_tax' ); + + wp_remove_object_terms( $p, $t, 'wptests_tax' ); + + $this->assertFalse( get_the_terms( $p, 'wptests_tax' ) ); + } +}