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

Props johnjamesjacoby.
See #37962.

git-svn-id: https://develop.svn.wordpress.org/trunk@38585 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-09-09 19:36:22 +00:00
parent 6c8c98fe5b
commit 6adcd15435
2 changed files with 20 additions and 1 deletions

View File

@ -3264,7 +3264,7 @@ class WP_Query {
$matched_taxonomy = reset( $queried_taxonomies );
$query = $tax_query_in_and[ $matched_taxonomy ];
if ( $query['terms'] ) {
if ( ! empty( $query['terms'] ) ) {
if ( 'term_id' == $query['field'] ) {
$term = get_term( reset( $query['terms'] ), $matched_taxonomy );
} else {

View File

@ -118,6 +118,25 @@ class Tests_Query extends WP_UnitTestCase {
unset( $q->query_vars['wptests_tax'] );
}
/**
* @ticket 37962
*/
public function test_get_queried_object_should_return_null_for_not_exists_tax_query() {
register_taxonomy( 'wptests_tax', 'post' );
$q = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'wptests_tax',
'operator' => 'NOT EXISTS',
),
),
) );
$queried_object = $q->get_queried_object();
$this->assertNull( $queried_object );
}
public function test_orderby_space_separated() {
global $wpdb;