Make WordPress Core

Ticket #36343: 36343.2.diff

File 36343.2.diff, 2.5 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/class-wp-tax-query.php

    diff --git src/wp-includes/class-wp-tax-query.php src/wp-includes/class-wp-tax-query.php
    index a842b2c..e220806 100644
    class WP_Tax_Query { 
    440440                                // Store the alias with this clause, so later siblings can use it.
    441441                                $clause['alias'] = $alias;
    442442
    443                                 $join .= " INNER JOIN $wpdb->term_relationships";
     443                                $join .= " LEFT JOIN $wpdb->term_relationships";
    444444                                $join .= $i ? " AS $alias" : '';
    445445                                $join .= " ON ($this->primary_table.$this->primary_id_column = $alias.object_id)";
    446446                        }
  • tests/phpunit/tests/query/taxQuery.php

    diff --git tests/phpunit/tests/query/taxQuery.php tests/phpunit/tests/query/taxQuery.php
    index 8248b19..7582eb2 100644
    class Tests_Query_TaxQuery extends WP_UnitTestCase { 
    410410        }
    411411
    412412        /**
     413         * @ticket 36343
     414         */
     415        public function test_tax_query_operator_not_exists_combined() {
     416                register_post_type( 'wptests_cpt1' );
     417                register_taxonomy( 'wptests_tax1', 'wptests_cpt1' );
     418                register_taxonomy( 'wptests_tax2', 'wptests_cpt1' );
     419
     420                $t1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) );
     421                $t2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax1' ) );
     422                $t3 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax2' ) );
     423
     424                $p1 = self::factory()->post->create( array( 'post_type' => 'wptests_cpt1' ) );
     425                $p2 = self::factory()->post->create( array( 'post_type' => 'wptests_cpt1' ) );
     426                $p3 = self::factory()->post->create( array( 'post_type' => 'wptests_cpt1' ) );
     427                $p4 = self::factory()->post->create( array( 'post_type' => 'wptests_cpt1' ) );
     428
     429                wp_set_object_terms( $p1, array( $t1 ), 'wptests_tax1' );
     430                wp_set_object_terms( $p2, array( $t2 ), 'wptests_tax1' );
     431                wp_set_object_terms( $p3, array( $t3 ), 'wptests_tax2' );
     432
     433                $q = new WP_Query( array(
     434                        'post_type' => 'wptests_cpt1',
     435                        'fields'    => 'ids',
     436                        'tax_query' => array(
     437                                'relation' => 'OR',
     438                                array(
     439                                        'taxonomy' => 'wptests_tax1',
     440                                        'operator' => 'NOT EXISTS',
     441                                ),
     442                                array(
     443                                        'taxonomy' => 'wptests_tax1',
     444                                        'field'    => 'slug',
     445                                        'terms'    => get_term_field( 'slug', $t1 ),
     446                                ),
     447                        ),
     448                ) );
     449
     450                unregister_post_type( 'wptests_cpt1' );
     451                unregister_taxonomy( 'wptests_tax1' );
     452                unregister_taxonomy( 'wptests_tax2' );
     453
     454                $this->assertEqualSets( array( $p1, $p3, $p4 ), $q->posts );
     455        }
     456
     457        /**
    413458         * @ticket 29181
    414459         */
    415460        public function test_tax_query_operator_exists() {