Make WordPress Core


Ignore:
Timestamp:
01/26/2015 07:03:09 PM (9 years ago)
Author:
boonebgorges
Message:

Ensure that 'hierarchical' is respected in get_terms() when multiple taxonomies are passed.

Previously, attempts to descend the family tree of each term were done using
the first taxonomy in the $taxonomies array, with the result that terms not
belonging to that taxonomy were not found and their children not properly
parsed. We fix this bug by fetching each term's taxonomy with the SQL query,
and then using that taxonomy to get the correct children for each term.

Fixes #31118.

File:
1 edited

Legend:

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

    r31284 r31285  
    10711071
    10721072    /**
     1073     * @ticket 31118
     1074     */
     1075    public function test_hierarchical_should_recurse_properly_for_all_taxonomies() {
     1076        register_taxonomy( 'wptests_tax1', 'post', array( 'hierarchical' => true ) );
     1077        register_taxonomy( 'wptests_tax2', 'post', array( 'hierarchical' => true ) );
     1078
     1079        $t1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax1' ) );
     1080        $t2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax1', 'parent' => $t1 ) );
     1081        $t3 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax1', 'parent' => $t2 ) );
     1082
     1083        $t4 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax2' ) );
     1084        $t5 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t4 ) );
     1085        $t6 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax2', 'parent' => $t5 ) );
     1086
     1087        $p = $this->factory->post->create();
     1088
     1089        wp_set_object_terms( $p, $t3, 'wptests_tax1' );
     1090        wp_set_object_terms( $p, $t6, 'wptests_tax2' );
     1091
     1092        $found = get_terms( array( 'wptests_tax1', 'wptests_tax2' ), array(
     1093            'hierarchical' => true,
     1094            'hide_empty' => true,
     1095            'fields' => 'ids',
     1096        ) );
     1097
     1098        /*
     1099         * Should contain all terms, since they all have non-empty descendants.
     1100         * To make the case clearer, test taxonomies separately.
     1101         */
     1102
     1103        // First taxonomy.
     1104        $this->assertContains( $t1, $found );
     1105        $this->assertContains( $t2, $found );
     1106        $this->assertContains( $t3, $found );
     1107
     1108        // Second taxonomy.
     1109        $this->assertContains( $t4, $found );
     1110        $this->assertContains( $t5, $found );
     1111        $this->assertContains( $t6, $found );
     1112    }
     1113
     1114    /**
    10731115     * @ticket 23261
    10741116     */
Note: See TracChangeset for help on using the changeset viewer.