Use FOUND_ROWS to calculate the max number of pages. Need to cleanup/eliminate _max_num_pages().

git-svn-id: https://develop.svn.wordpress.org/trunk@4455 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2006-11-08 09:13:11 +00:00
parent a9b0944ae2
commit 6a3029d8d5
2 changed files with 10 additions and 3 deletions

View File

@ -472,7 +472,7 @@ function previous_posts_link($label='« Previous Page') {
}
function _max_num_pages() {
static $max_num_pages;
global $max_num_pages;
global $wpdb, $wp_query;
if (isset($max_num_pages)) return $max_num_pages;

View File

@ -981,11 +981,18 @@ class WP_Query {
$orderby = apply_filters('posts_orderby', $q['orderby']);
$distinct = apply_filters('posts_distinct', $distinct);
$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->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.
if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
$status = get_post_status($this->posts[0]);