Taxonomy: Ensure the child_of argument of get_terms() works as expected with 'fields' => 'id=>name' or 'id=>slug'.

Props Howdy_McGee, deepaklalwani, planvova.
Fixes #46768.

git-svn-id: https://develop.svn.wordpress.org/trunk@48663 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-07-28 14:21:54 +00:00
parent faa6036d08
commit 6e66f08ec9
2 changed files with 79 additions and 2 deletions

View File

@ -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;
}

View File

@ -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
*/