return $wp_query->get($var);
}
-
/**
- * Retrieve the currently-queried object. Wrapper for $wp_query->get_queried_object()
+ * Retrieve the currently-queried object. Wrapper for $wp_query->get_queried_object()
*
* @uses WP_Query::get_queried_object
*
}
/*
- * The Loop. Post loop control.
+ * The Loop. Post loop control.
*/
/**
var $query_vars_hash = false;
/**
- * Whether query vars have changed since the initial parse_query() call. Used to catch modifications to query vars made
+ * Whether query vars have changed since the initial parse_query() call. Used to catch modifications to query vars made
* via pre_get_posts hooks.
*
* @since 3.1.1
if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']);
if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']);
- // Compat. Map subpost to attachment.
+ // Compat. Map subpost to attachment.
if ( '' != $qv['subpost'] )
$qv['attachment'] = $qv['subpost'];
if ( '' != $qv['subpost_id'] )
$this->is_page = true;
$this->is_single = false;
} else {
- // Look for archive queries. Dates, categories, authors, search, post type archives.
+ // Look for archive queries. Dates, categories, authors, search, post type archives.
if ( !empty($qv['s']) ) {
$this->is_search = true;
}
if ( '' != $qv['pagename'] ) {
- $this->queried_object =& get_page_by_path($qv['pagename']);
+ $this->queried_object = get_page_by_path($qv['pagename']);
if ( !empty($this->queried_object) )
$this->queried_object_id = (int) $this->queried_object->ID;
else
if ( !empty($q['sentence']) ) {
$q['search_terms'] = array($q['s']);
} else {
- preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q['s'], $matches);
+ preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches);
$q['search_terms'] = array_map('_search_terms_tidy', $matches[0]);
}
$n = !empty($q['exact']) ? '' : '%';
// MIME-Type stuff for attachment browsing
- if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] ) {
- $table_alias = $post_status_join ? $wpdb->posts : '';
- $whichmimetype = wp_post_mime_type_where($q['post_mime_type'], $table_alias);
- }
+ if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] )
+ $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts );
$where .= $search . $whichauthor . $whichmimetype;
switch ( $orderby ) {
case 'menu_order':
+ $orderby = "$wpdb->posts.menu_order";
break;
case 'ID':
$orderby = "$wpdb->posts.ID";
}
if ( !empty($r_status) ) {
if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can($edit_others_cap) )
- $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";
+ $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $r_status ) . "))";
else
$statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
}
if ( !empty($p_status) ) {
if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can($read_private_cap) )
- $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";
+ $statuswheres[] = "($wpdb->posts.post_author = $user_ID " . "AND (" . join( ' OR ', $p_status ) . "))";
else
$statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
}
$where .= " OR $wpdb->posts.post_status = '$state'";
}
- if ( is_admin() ) {
+ if ( $this->is_admin ) {
// Add protected states that should show in the admin all list.
$admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) );
foreach ( (array) $admin_all_states as $state )
// Paging
if ( empty($q['nopaging']) && !$this->is_singular ) {
$page = absint($q['paged']);
- if ( empty($page) )
+ if ( !$page )
$page = 1;
if ( empty($q['offset']) ) {
- $pgstrt = '';
$pgstrt = ($page - 1) * $q['posts_per_page'] . ', ';
- $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
} else { // we're ignoring $page and using 'offset'
$q['offset'] = absint($q['offset']);
$pgstrt = $q['offset'] . ', ';
- $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
}
+ $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
}
// Comments feeds
$pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
- // Apply post-paging filters on where and join. Only plugins that
+ // Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks.
if ( !$q['suppress_filters'] ) {
$where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
$$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
}
- // Announce current selection parameters. For use by caching plugins.
+ // Announce current selection parameters. For use by caching plugins.
do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
- // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above.
+ // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above.
if ( !$q['suppress_filters'] ) {
$where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) );
$groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) );
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'] )
- $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
+ $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
+
+ if ( !$q['suppress_filters'] ) {
+ $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) );
+ }
if ( 'ids' == $q['fields'] ) {
$this->posts = $wpdb->get_col($this->request);
return $r;
}
- $this->posts = $wpdb->get_results($this->request);
+ $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
+ $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
+
+ if ( $split_the_query ) {
+ // First get the IDs and then fill in the objects
- // Raw results filter. Prior to status checks.
+ $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
+
+ $this->request = apply_filters( 'posts_request_ids', $this->request, $this );
+
+ $ids = $wpdb->get_col( $this->request );
+
+ if ( $ids ) {
+ $this->set_found_posts( $q, $limits );
+
+ _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
+
+ $this->posts = array_map( 'get_post', $ids );
+ } else {
+ $this->found_posts = $this->max_num_pages = 0;
+ $this->posts = array();
+ }
+ } else {
+ $this->posts = $wpdb->get_results( $this->request );
+ $this->set_found_posts( $q, $limits );
+ }
+
+ // Raw results filter. Prior to status checks.
if ( !$q['suppress_filters'] )
$this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
$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]);
}
}
- if ( $this->is_preview && current_user_can( $edit_cap, $this->posts[0]->ID ) )
+ if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) )
$this->posts[0] = apply_filters_ref_array('the_preview', array( $this->posts[0], &$this ));
}
array_splice($this->posts, $i, 1);
// Move to front, after other stickies
array_splice($this->posts, $sticky_offset, 0, array($sticky_post));
- // Increment the sticky offset. The next sticky will be placed at this offset.
+ // Increment the sticky offset. The next sticky will be placed at this offset.
$sticky_offset++;
// Remove post from sticky posts array
$offset = array_search($sticky_post->ID, $sticky_posts);
return $this->posts;
}
+ function set_found_posts( $q, $limits ) {
+ global $wpdb;
+
+ if ( $q['no_found_rows'] || empty( $limits ) )
+ return;
+
+ $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
+ $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'] );
+ }
+
/**
* Set up the next post and iterate current post index.
*
if ( isset($this->queried_object) )
return $this->queried_object;
- $this->queried_object = NULL;
+ $this->queried_object = null;
$this->queried_object_id = 0;
if ( $this->is_category || $this->is_tag || $this->is_tax ) {
$this->queried_object = get_post_type_object( $this->get('post_type') );
} elseif ( $this->is_posts_page ) {
$page_for_posts = get_option('page_for_posts');
- $this->queried_object = & get_page( $page_for_posts );
+ $this->queried_object = get_page( $page_for_posts );
$this->queried_object_id = (int) $this->queried_object->ID;
} elseif ( $this->is_singular && !is_null($this->post) ) {
$this->queried_object = $this->post;
return (bool) $this->is_date;
}
-
/**
* Is the query for a day archive?
*
return true;
}
-?>