diff --git wp-includes/query.php wp-includes/query.php
index d70348c..e34b942 100644
--- wp-includes/query.php
+++ wp-includes/query.php
@@ -2600,8 +2600,27 @@ class WP_Query {
 		if ( !$q['no_found_rows'] && !empty($limits) )
 			$found_rows = 'SQL_CALC_FOUND_ROWS';
 
-		$this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
-		if ( !$q['suppress_filters'] )
+        $ids_request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
+        $ids_res = $wpdb->get_results($ids_request);
+
+        if ( !$q['no_found_rows'] && !empty($limits) ) {
+			$found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
+			$this->found_posts = $wpdb->get_var( $found_posts_query );
+			$this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
+			$this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
+		}
+
+        $ids_list = array();
+        foreach ( $ids_res as $id_row ) {
+            $ids_list[] = $id_row->ID;
+        }
+        $ids_where = " AND 0";
+        if ( count($ids_list) > 0 ) {
+            $ids_where = " AND {$wpdb->posts}.ID IN (" . implode(',', $ids_list) . ")";
+        }
+        
+		$this->request = " SELECT $distinct $fields FROM $wpdb->posts WHERE 1=1 $ids_where $orderby";
+        if ( !$q['suppress_filters'] )
 			$this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
 
 		if ( 'ids' == $q['fields'] ) {
@@ -2639,13 +2658,6 @@ class WP_Query {
 			$this->comment_count = count($this->comments);
 		}
 
-		if ( !$q['no_found_rows'] && !empty($limits) ) {
-			$found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
-			$this->found_posts = $wpdb->get_var( $found_posts_query );
-			$this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
-			$this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
-		}
-
 		// Check post status to determine if post should be displayed.
 		if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
 			$status = get_post_status($this->posts[0]);
