From dfb75f083333cb68626eb55bc856883604b9ca14 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 29 May 2014 05:48:14 +0000 Subject: [PATCH] When parsing the main query, if `s` is set to empty: `?s=` and `$this->is_main_query() && array_key_exists( 's', $this->query )` - kill the query instead of loading the homepage. This will load the search page with no results. Fixes #11330. Built from https://develop.svn.wordpress.org/trunk@28612 git-svn-id: http://core.svn.wordpress.org/trunk@28436 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index e98f73e790..4b5aa1730c 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1510,11 +1510,10 @@ class WP_Query { $this->is_page = true; $this->is_single = false; } else { - // Look for archive queries. Dates, categories, authors, search, post type archives. - if ( !empty($qv['s']) ) { + // Look for archive queries. Dates, categories, authors, search, post type archives. + if ( ! empty( $qv['s'] ) || ( $this->is_main_query() && array_key_exists( 's', $this->query ) ) ) $this->is_search = true; - } if ( '' !== $qv['second'] ) { $this->is_time = true; @@ -2261,6 +2260,11 @@ class WP_Query { $q['nopaging'] = false; } } + + if ( $this->is_search ) { + $search = 'AND 0'; + } + if ( $this->is_feed ) { // This overrides posts_per_page. if ( ! empty( $q['posts_per_rss'] ) ) { @@ -2876,7 +2880,7 @@ class WP_Query { } // Comments feeds - if ( $this->is_comment_feed && ( $this->is_archive || $this->is_search || !$this->is_singular ) ) { + if ( $this->is_comment_feed && ( $this->is_archive || ( $this->is_search && ! empty( $q['s'] ) ) || !$this->is_singular ) ) { if ( $this->is_archive || $this->is_search ) { $cjoin = "JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join "; $cwhere = "WHERE comment_approved = '1' $where";