WordPress.org

Make WordPress Core

Changeset 38585


Ignore:
Timestamp:
09/09/2016 07:36:22 PM (22 months ago)
Author:
boonebgorges
Message:

Query: Avoid PHP notice in get_queried_object() when query contains NOT EXISTS tax query.

Props johnjamesjacoby.
See #37962.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r38491 r38585  
    32653265                    $query = $tax_query_in_and[ $matched_taxonomy ];
    32663266
    3267                     if ( $query['terms'] ) {
     3267                    if ( ! empty( $query['terms'] ) ) {
    32683268                        if ( 'term_id' == $query['field'] ) {
    32693269                            $term = get_term( reset( $query['terms'] ), $matched_taxonomy );
  • trunk/tests/phpunit/tests/query.php

    r36484 r38585  
    119119    }
    120120
     121    /**
     122     * @ticket 37962
     123     */
     124    public function test_get_queried_object_should_return_null_for_not_exists_tax_query() {
     125        register_taxonomy( 'wptests_tax', 'post' );
     126
     127        $q = new WP_Query( array(
     128            'tax_query' => array(
     129                array(
     130                    'taxonomy' => 'wptests_tax',
     131                    'operator' => 'NOT EXISTS',
     132                ),
     133            ),
     134        ) );
     135
     136        $queried_object = $q->get_queried_object();
     137        $this->assertNull( $queried_object );
     138    }
     139
    121140    public function test_orderby_space_separated() {
    122141        global $wpdb;
Note: See TracChangeset for help on using the changeset viewer.