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:
ryan 2006-11-08 09:13:11 +00:00
parent 70b9f6e5ed
commit 19942073ea
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]);