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
This commit is contained in:
Ryan Boren 2010-03-10 18:37:03 +00:00
parent 8de3d20dc2
commit 78ef621011
2 changed files with 9 additions and 3 deletions

View File

@ -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) );
}
/**

View File

@ -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 );