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.

git-svn-id: https://develop.svn.wordpress.org/trunk@31366 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-02-07 19:49:17 +00:00
parent fa1a382dff
commit bdda122e7f
2 changed files with 42 additions and 9 deletions

View File

@@ -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 );
}
}
}
}