From 19942073ea33c2db03a3c332a6310e1563e683fa Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 8 Nov 2006 09:13:11 +0000 Subject: [PATCH] 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 --- wp-includes/link-template.php | 2 +- wp-includes/query.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index c4002bdee..e9ecb63cc 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -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; diff --git a/wp-includes/query.php b/wp-includes/query.php index fa8e704e4..9de68a292 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -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]);