From 78ef621011cf6ce5be7af3f25320c0739b6c6284 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 10 Mar 2010 18:37:03 +0000 Subject: [PATCH] Add no_found_rows argument to WP_Query::get_posts() to allow forcibly defeating SQL_CALC_FOUND_ROWS. Use no_found_rows for the query in get_boundary_post(). fixes #12557 git-svn-id: https://develop.svn.wordpress.org/trunk@13647 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/link-template.php | 2 +- wp-includes/query.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 5aab248c32..c95fb8ce20 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1158,7 +1158,7 @@ function get_boundary_post($in_same_cat = false, $excluded_categories = '', $sta $order = $start ? 'ASC' : 'DESC'; - return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) ); + return get_posts( array('numberposts' => 1, 'no_found_rows' => true, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) ); } /** diff --git a/wp-includes/query.php b/wp-includes/query.php index a3bae6de38..e47a8db21d 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1672,6 +1672,12 @@ class WP_Query { $q['page'] = absint($q['page']); } + // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. + if ( isset($q['no_found_rows']) ) + $q['no_found_rows'] = (bool) $q['no_found_rows']; + else + $q['no_found_rows'] = false; + // If a month is specified in the querystring, load that month if ( $q['m'] ) { $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); @@ -2331,7 +2337,7 @@ class WP_Query { if ( !empty( $orderby ) ) $orderby = 'ORDER BY ' . $orderby; $found_rows = ''; - if ( !empty($limits) ) + 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"; @@ -2356,7 +2362,7 @@ class WP_Query { $this->comment_count = count($this->comments); } - if ( !empty($limits) ) { + if ( !$q['no_found_rows'] && !empty($limits) ) { $found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' ); $this->found_posts = $wpdb->get_var( $found_posts_query ); $this->found_posts = apply_filters( 'found_posts', $this->found_posts );