diff --git a/src/wp-includes/taxonomy-functions.php b/src/wp-includes/taxonomy-functions.php index c007ffed4d..3a3fd2a6cc 100644 --- a/src/wp-includes/taxonomy-functions.php +++ b/src/wp-includes/taxonomy-functions.php @@ -751,9 +751,9 @@ function get_term( $term, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { // If there are two terms with the same ID, split the other one to a new term. $new_term_id = _split_shared_term( $_term->term_id, $_term->term_taxonomy_id ); - // If no split occurred, this is an invalid request. + // If no split occurred, this is an invalid request. Return null (not WP_Error) for back compat. if ( $new_term_id === $_term->term_id ) { - return new WP_Error( 'invalid_term', __( 'Empty Term' ) ); + return null; // The term has been split. Refetch the term from the proper taxonomy. } else { diff --git a/tests/phpunit/tests/term/getTerm.php b/tests/phpunit/tests/term/getTerm.php index 481627c463..1a6f8fd63d 100644 --- a/tests/phpunit/tests/term/getTerm.php +++ b/tests/phpunit/tests/term/getTerm.php @@ -106,4 +106,12 @@ class Tests_Term_GetTerm extends WP_UnitTestCase { $this->assertInternalType( 'int', $found->count ); $this->assertInternalType( 'int', $found->term_group ); } + + /** + * @ticket 34332 + */ + public function test_should_return_null_when_provided_taxonomy_does_not_match_actual_term_taxonomy() { + $term_id = self::$factory->term->create( array( 'taxonomy' => 'post_tag' ) ); + $this->assertNull( get_term( $term_id, 'category' ) ); + } }