From 44bb3833717a13429e1b6b4c6ae7cc2278de7c50 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 16 Oct 2014 22:06:46 +0000 Subject: [PATCH] Remove invalid `continue` calls from WP_Tax_Query::get_sql_for_clause(). This was leftover code from the previous implementation, which used a `foreach()` loop. See [29901]. Props nofearinc. See #29738, #29718. git-svn-id: https://develop.svn.wordpress.org/trunk@29931 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 4 +-- tests/phpunit/tests/term/query.php | 53 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 63b505417f..dcf1b56b37 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1041,7 +1041,7 @@ class WP_Tax_Query { } elseif ( 'NOT IN' == $operator ) { if ( empty( $terms ) ) { - continue; + return $sql; } $terms = implode( ',', $terms ); @@ -1055,7 +1055,7 @@ class WP_Tax_Query { } elseif ( 'AND' == $operator ) { if ( empty( $terms ) ) { - continue; + return $sql; } $num_terms = count( $terms ); diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 70f3987653..57dac3610c 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -352,4 +352,57 @@ class Tests_Tax_Query extends WP_UnitTestCase { _unregister_taxonomy( 'wptests_tax' ); } + /** + * @ticket 29738 + */ + public function test_get_sql_operator_not_in_empty_terms() { + register_taxonomy( 'wptests_tax', 'post' ); + + $tq = new WP_Tax_Query( array( + 'relation' => 'OR', + array( + 'taxonomy' => 'wptests_tax', + 'field' => 'term_id', + 'operator' => 'NOT IN', + 'terms' => array(), + ), + ) ); + + global $wpdb; + $expected = array( + 'join' => '', + 'where' => '', + ); + + $this->assertSame( $expected, $tq->get_sql( $wpdb->posts, 'ID' ) ); + + _unregister_taxonomy( 'wptests_tax' ); + } + + /** + * @ticket 29738 + */ + public function test_get_sql_operator_and_empty_terms() { + register_taxonomy( 'wptests_tax', 'post' ); + + $tq = new WP_Tax_Query( array( + 'relation' => 'OR', + array( + 'taxonomy' => 'wptests_tax', + 'field' => 'term_id', + 'operator' => 'AND', + 'terms' => array(), + ), + ) ); + + global $wpdb; + $expected = array( + 'join' => '', + 'where' => '', + ); + + $this->assertSame( $expected, $tq->get_sql( $wpdb->posts, 'ID' ) ); + + _unregister_taxonomy( 'wptests_tax' ); + } }