Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 15776)
+++ wp-includes/query.php	(working copy)
@@ -2186,25 +2186,34 @@
 		// Apply post-paging filters on where and join.  Only plugins that
 		// manipulate paging queries should use these hooks.
 		if ( !$q['suppress_filters'] ) {
-			$distinct	= apply_filters_ref_array( 'posts_distinct',	array( $distinct, &$this ) );
-			$fields		= apply_filters_ref_array( 'posts_fields',		array( $fields, &$this ) );
-			$where		= apply_filters_ref_array( 'posts_where_paged',	array( $where, &$this ) );
-			$join		= apply_filters_ref_array( 'posts_join_paged',	array( $join, &$this ) );
-			$groupby	= apply_filters_ref_array( 'posts_groupby',		array( $groupby, &$this ) );
-			$orderby	= apply_filters_ref_array( 'posts_orderby',		array( $orderby, &$this ) );
-			$limits		= apply_filters_ref_array( 'post_limits',		array( $limits, &$this ) );	
-
-			// Also apply a filter on all clauses at once, for convenience
+			// clause filter variables
+			$variables = array(
+				'distinct' => 'posts_distinct', 
+				'fields'   => 'posts_fields', 
+				'where'    => 'posts_where_paged', 
+				'join'     => 'posts_join_paged', 
+				'groupby'  => 'posts_groupby', 
+				'orderby'  => 'posts_orderby', 
+				'limits'   => 'post_limits', 
+			);
+			// build clauses array and run filters once per clause
 			$clauses = array();
-			foreach ( array('distinct', 'fields', 'where', 'join', 'groupby', 'orderby', 'limits') as $var ) {
-				$clauses[ $var ] = $$var;
-				unset( $$var );	// so we can use EXTR_SKIP below
+			foreach ( $variables as $variable_name => $filter_name ) {
+				$clauses[ $variable_name ] = apply_filters_ref_array( $filter_name, array( $$variable_name, &$this ) );
+				unset( $$variable_name ); // for extract() with EXTR_SKIP parameter
 			}
-
+			// run filter for all clauses at once
 			$clauses = apply_filters_ref_array( 'wp_query_clauses', array( $clauses, &$this ) );
-
-			extract( $clauses, EXTR_SKIP );
+			if ( is_array( $clauses ) ) {
+				extract( $clauses, EXTR_SKIP );
+			}
 			unset( $clauses );
+			// prevent notices in case a filter removed clause variable(s)
+			foreach ( $variables as $variable_name => $filter_name ) {
+				if ( !isset( ${$variable_name} ) ) {
+					$$variable_name = '';
+				}
+			}
 		}
 
 		// Announce current selection parameters.  For use by caching plugins.
@@ -2223,10 +2232,10 @@
 
 		if ( ! empty($groupby) )
 			$groupby = 'GROUP BY ' . $groupby;
-		if ( !empty( $orderby ) )
+		if ( ! empty( $orderby ) )
 			$orderby = 'ORDER BY ' . $orderby;
 		$found_rows = '';
-		if ( !$q['no_found_rows'] && !empty($limits) )
+		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";
