From 90639872e8c855756df575f414c96f76973fe233 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 7 Feb 2015 19:50:24 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@31366 git-svn-id: http://core.svn.wordpress.org/trunk@31347 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 18 ++++++++++-------- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index c38a11c083..27d8c26fa4 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -3900,15 +3900,17 @@ class WP_Query { // For other tax queries, grab the first term from the first clause. $tax_query_in_and = wp_list_filter( $this->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' ); - $queried_taxonomies = array_keys( $tax_query_in_and ); - $matched_taxonomy = reset( $queried_taxonomies ); - $query = $tax_query_in_and[ $matched_taxonomy ]; + if ( ! empty( $tax_query_in_and ) ) { + $queried_taxonomies = array_keys( $tax_query_in_and ); + $matched_taxonomy = reset( $queried_taxonomies ); + $query = $tax_query_in_and[ $matched_taxonomy ]; - if ( $query['terms'] ) { - if ( 'term_id' == $query['field'] ) { - $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); - } else { - $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); + if ( $query['terms'] ) { + if ( 'term_id' == $query['field'] ) { + $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); + } else { + $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); + } } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5807318907..2d54940304 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31365'; +$wp_version = '4.2-alpha-31366'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.