diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 8b8fea4c9b..15198a3356 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -620,10 +620,10 @@ class WP_Term_Query { $selects = array( 'COUNT(*)' ); break; case 'id=>name': - $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' ); + $selects = array( 't.term_id', 't.name', 'tt.parent', 'tt.count', 'tt.taxonomy' ); break; case 'id=>slug': - $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' ); + $selects = array( 't.term_id', 't.slug', 'tt.parent', 'tt.count', 'tt.taxonomy' ); break; } diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index 2c20a191eb..a22f90a7a9 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -719,6 +719,83 @@ class Tests_Term_getTerms extends WP_UnitTestCase { $this->assertEquals( 1, count( $terms ) ); } + /** + * @ticket 46768 + */ + function test_get_terms_child_of_fields_id_name() { + $parent = self::factory()->category->create(); + $child = self::factory()->category->create( + array( + 'parent' => $parent, + 'slug' => 'test-1', + 'name' => 'Test 1', + ) + ); + $child2 = self::factory()->category->create( + array( + 'parent' => $parent, + 'slug' => 'test-2', + 'name' => 'Test 2', + ) + ); + + $terms = get_terms( + 'category', + array( + 'child_of' => $parent, + 'hide_empty' => false, + 'fields' => 'id=>name', + ) + ); + + $this->assertEquals( + array( + $child => 'Test 1', + $child2 => 'Test 2', + ), + $terms + ); + + } + + /** + * @ticket 46768 + */ + function test_get_terms_child_of_fields_id_slug() { + $parent = self::factory()->category->create(); + $child = self::factory()->category->create( + array( + 'parent' => $parent, + 'slug' => 'test-1', + 'name' => 'Test 1', + ) + ); + $child2 = self::factory()->category->create( + array( + 'parent' => $parent, + 'slug' => 'test-2', + 'name' => 'Test 2', + ) + ); + + $terms = get_terms( + 'category', + array( + 'child_of' => $parent, + 'hide_empty' => false, + 'fields' => 'id=>slug', + ) + ); + + $this->assertEquals( + array( + $child => 'test-1', + $child2 => 'test-2', + ), + $terms + ); + } + /** * @ticket 31118 */