Use FOUND_ROWS to calculate the max number of pages. Need to cleanup/eliminate _max_num_pages().
git-svn-id: http://svn.automattic.com/wordpress/trunk@4455 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
70b9f6e5ed
commit
19942073ea
|
@ -472,7 +472,7 @@ function previous_posts_link($label='« Previous Page') {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _max_num_pages() {
|
function _max_num_pages() {
|
||||||
static $max_num_pages;
|
global $max_num_pages;
|
||||||
global $wpdb, $wp_query;
|
global $wpdb, $wp_query;
|
||||||
|
|
||||||
if (isset($max_num_pages)) return $max_num_pages;
|
if (isset($max_num_pages)) return $max_num_pages;
|
||||||
|
|
|
@ -981,11 +981,18 @@ class WP_Query {
|
||||||
$orderby = apply_filters('posts_orderby', $q['orderby']);
|
$orderby = apply_filters('posts_orderby', $q['orderby']);
|
||||||
$distinct = apply_filters('posts_distinct', $distinct);
|
$distinct = apply_filters('posts_distinct', $distinct);
|
||||||
$fields = apply_filters('posts_fields', "$wpdb->posts.*");
|
$fields = apply_filters('posts_fields', "$wpdb->posts.*");
|
||||||
$request = " SELECT $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby ORDER BY $orderby $limits";
|
$found_rows = '';
|
||||||
|
if ( !empty($limits) )
|
||||||
|
$found_rows = 'SQL_CALC_FOUND_ROWS';
|
||||||
|
$request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby ORDER BY $orderby $limits";
|
||||||
$this->request = apply_filters('posts_request', $request);
|
$this->request = apply_filters('posts_request', $request);
|
||||||
|
|
||||||
$this->posts = $wpdb->get_results($this->request);
|
$this->posts = $wpdb->get_results($this->request);
|
||||||
|
if ( !empty($limits) ) {
|
||||||
|
$num_rows = $wpdb->get_var('SELECT FOUND_ROWS()');
|
||||||
|
global $max_num_pages;
|
||||||
|
$max_num_pages = $num_rows / $q['posts_per_page'];
|
||||||
|
}
|
||||||
// Check post status to determine if post should be displayed.
|
// Check post status to determine if post should be displayed.
|
||||||
if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
|
if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
|
||||||
$status = get_post_status($this->posts[0]);
|
$status = get_post_status($this->posts[0]);
|
||||||
|
|
Loading…
Reference in New Issue