From ca1439191781cb83a82e3479e4db0f88afce228a Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 4 Oct 2012 13:16:47 +0000 Subject: [PATCH] An empty taxonomy query should return no results rather than all posts. Props wonderboymusic. fixes #20604 git-svn-id: https://develop.svn.wordpress.org/trunk@22109 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 62d5e31459..a37e700a92 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -660,23 +660,26 @@ class WP_Tax_Query { $join = ''; $where = array(); $i = 0; + $count = count( $this->queries ); - foreach ( $this->queries as $query ) { + foreach ( $this->queries as $index => $query ) { $this->clean_query( $query ); - if ( is_wp_error( $query ) ) { + if ( is_wp_error( $query ) ) return self::$no_results; - } extract( $query ); if ( 'IN' == $operator ) { if ( empty( $terms ) ) { - if ( 'OR' == $this->relation ) + if ( 'OR' == $this->relation ) { + if ( ( $index + 1 === $count ) && empty( $where ) ) + return self::$no_results; continue; - else + } else { return self::$no_results; + } } $terms = implode( ',', $terms ); @@ -720,7 +723,7 @@ class WP_Tax_Query { $i++; } - if ( !empty( $where ) ) + if ( ! empty( $where ) ) $where = ' AND ( ' . implode( " $this->relation ", $where ) . ' )'; else $where = '';