Make WordPress Core


Ignore:
Timestamp:
02/07/2015 07:49:17 PM (10 years ago)
Author:
boonebgorges
Message:

In WP_Query::get_queried_object(), avoid PHP notices when is_tax is paired with an empty tax_query.

It's possible to have an empty tax_query and is_tax=true when the initial
query contains a taxonomy var (and is processed as such during
WP_Query::parse_query()) but the taxonomy var is unset during a 'parse_query'
callback. While this kind of behavior is not necessarily something we need to
support, we should continue to avoid PHP notices in such cases, as we did prior
to WP 4.1.

Fixes #31246.

File:
1 edited

Legend:

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

    r31340 r31366  
    39013901                $tax_query_in_and = wp_list_filter( $this->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' );
    39023902
    3903                 $queried_taxonomies = array_keys( $tax_query_in_and );
    3904                 $matched_taxonomy = reset( $queried_taxonomies );
    3905                 $query = $tax_query_in_and[ $matched_taxonomy ];
    3906 
    3907                 if ( $query['terms'] ) {
    3908                     if ( 'term_id' == $query['field'] ) {
    3909                         $term = get_term( reset( $query['terms'] ), $matched_taxonomy );
    3910                     } else {
    3911                         $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );
     3903                if ( ! empty( $tax_query_in_and ) ) {
     3904                    $queried_taxonomies = array_keys( $tax_query_in_and );
     3905                    $matched_taxonomy = reset( $queried_taxonomies );
     3906                    $query = $tax_query_in_and[ $matched_taxonomy ];
     3907
     3908                    if ( $query['terms'] ) {
     3909                        if ( 'term_id' == $query['field'] ) {
     3910                            $term = get_term( reset( $query['terms'] ), $matched_taxonomy );
     3911                        } else {
     3912                            $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy );
     3913                        }
    39123914                    }
    39133915                }
Note: See TracChangeset for help on using the changeset viewer.