Make WordPress Core


Ignore:
Timestamp:
10/10/2017 04:45:01 PM (7 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/query.php

    r41377 r41809  
    430430
    431431    /**
     432     * @ticket 41293
     433     */
     434    public function test_should_allow_same_args_with_the_get_terms() {
     435        register_post_type( 'wptests_pt' );
     436        register_taxonomy( 'wptests_tax', 'wptests_pt' );
     437        $t1 = self::factory()->term->create( array(
     438            'taxonomy' => 'wptests_tax',
     439            'name' => 'foo',
     440            'slug' => 'bar',
     441        ) );
     442        $t2 = self::factory()->term->create( array(
     443            'taxonomy' => 'wptests_tax',
     444            'name' => 'bar',
     445            'slug' => 'foo',
     446        ) );
     447
     448        $p = self::factory()->post->create( array(
     449            'post_type' => 'wptests_pt',
     450        ) );
     451
     452        wp_set_object_terms( $p, array( $t1, $t2 ), 'wptests_tax' );
     453
     454        $expected = wp_get_post_terms( $p, 'wptests_tax', array(
     455            'fields' => 'ids',
     456        ) );
     457
     458        $found1 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
     459            'fields' => 'id=>parent',
     460        ) ) );
     461
     462        $found2 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
     463            'fields' => 'id=>slug',
     464        ) ) );
     465
     466        $found3 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
     467            'fields' => 'id=>name',
     468        ) ) );
     469
     470        $this->assertSame( $expected, $found1 );
     471        $this->assertSame( $expected, $found2 );
     472        $this->assertSame( $expected, $found3 );
     473    }
     474
     475    /**
    432476     * @ticket 41796
    433477     */
Note: See TracChangeset for help on using the changeset viewer.