diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index 27061e7266..f2ed10895c 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -107,7 +107,7 @@ function get_the_category( $id = false ) { */ function get_the_category_by_ID( $cat_ID ) { $cat_ID = (int) $cat_ID; - $category = get_term( $cat_ID, 'category' ); + $category = get_term( $cat_ID ); if ( is_wp_error( $category ) ) { return $category; diff --git a/tests/phpunit/tests/category/getTheCategoryById.php b/tests/phpunit/tests/category/getTheCategoryById.php new file mode 100644 index 0000000000..3b1a4e4825 --- /dev/null +++ b/tests/phpunit/tests/category/getTheCategoryById.php @@ -0,0 +1,53 @@ +category->create( array( + 'name' => 'Foo', + ) ); + + $found = get_the_category_by_ID( $c ); + + $this->assertSame( 'Foo', $found ); + } + + /** + * @ticket 42771 + */ + public function test_should_return_link_for_term_from_another_taxonomy_on_primed_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'name' => 'Foo', + ) ); + + $term = get_term( $t ); + + $found = get_the_category_by_ID( $t ); + + $this->assertSame( 'Foo', $found ); + } + + /** + * @ticket 42771 + */ + public function test_should_return_link_for_term_from_another_taxonomy_on_empty_cache() { + register_taxonomy( 'wptests_tax', 'post' ); + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'name' => 'Foo', + ) ); + + clean_term_cache( $t ); + + $found = get_the_category_by_ID( $t ); + + $this->assertSame( 'Foo', $found ); + } +}