mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Taxonomy: Don't discard keys when merging queried terms from different taxonomies.
For values of `fields` like `id=>parent`, the keys of the array must be maintained as part of the query results. Introduced as part of #40496. See [38667], [40513]. Props miyauchi, dany2217, pcarvalho. Fixes #41293. git-svn-id: https://develop.svn.wordpress.org/trunk@41809 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -428,6 +428,50 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( $term_ids[1], $term_ids[0], 1 ), wp_list_pluck( $terms, 'term_id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41293
|
||||
*/
|
||||
public function test_should_allow_same_args_with_the_get_terms() {
|
||||
register_post_type( 'wptests_pt' );
|
||||
register_taxonomy( 'wptests_tax', 'wptests_pt' );
|
||||
$t1 = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'foo',
|
||||
'slug' => 'bar',
|
||||
) );
|
||||
$t2 = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'name' => 'bar',
|
||||
'slug' => 'foo',
|
||||
) );
|
||||
|
||||
$p = self::factory()->post->create( array(
|
||||
'post_type' => 'wptests_pt',
|
||||
) );
|
||||
|
||||
wp_set_object_terms( $p, array( $t1, $t2 ), 'wptests_tax' );
|
||||
|
||||
$expected = wp_get_post_terms( $p, 'wptests_tax', array(
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$found1 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
|
||||
'fields' => 'id=>parent',
|
||||
) ) );
|
||||
|
||||
$found2 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
|
||||
'fields' => 'id=>slug',
|
||||
) ) );
|
||||
|
||||
$found3 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
|
||||
'fields' => 'id=>name',
|
||||
) ) );
|
||||
|
||||
$this->assertSame( $expected, $found1 );
|
||||
$this->assertSame( $expected, $found2 );
|
||||
$this->assertSame( $expected, $found3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41796
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user