From 75453e5e2dc2825dd9d2152ef89250a99baf5691 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 20 Nov 2010 21:10:20 +0000 Subject: [PATCH] If the queried term does not exist make sure no posts are returned in the query rather than falling through to querying all posts. Fixes 404s when querying cats that do not exist. see #12891 git-svn-id: https://develop.svn.wordpress.org/trunk@16511 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/query.php | 8 ++++++-- wp-includes/taxonomy.php | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 756e5e5c52..09c507b47e 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1947,8 +1947,12 @@ class WP_Query { if ( !empty( $this->tax_query ) ) { $clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) ); - $join .= $clauses['join']; - $where .= $clauses['where']; + if ( empty($clauses['join']) && empty($clauses['where']) ) { + $where .= ' AND 0 = 1'; + } else { + $join .= $clauses['join']; + $where .= $clauses['where']; + } if ( $this->is_tax ) { if ( empty($post_type) ) { diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 8135cdddda..977e9bf16f 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -539,7 +539,7 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) { foreach ( $taxonomies as $taxonomy ) { if ( ! taxonomy_exists( $taxonomy ) ) - return ' AND 0 = 1'; + return array( 'join' => '', 'where' => ' AND 0 = 1'); } $taxonomies = "'" . implode( "', '", $taxonomies ) . "'"; @@ -592,6 +592,7 @@ function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) { )"; } } + return compact( 'join', 'where' ); }