| 1 | Index: wp-includes/query.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/query.php (revision 18607) |
|---|
| 4 | +++ wp-includes/query.php (working copy) |
|---|
| 5 | @@ -2591,16 +2591,17 @@ |
|---|
| 6 | $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | - if ( ! empty($groupby) ) |
|---|
| 10 | - $groupby = 'GROUP BY ' . $groupby; |
|---|
| 11 | + if ( ! empty($groupby) ) { |
|---|
| 12 | + $groupby = 'GROUP BY ' . $groupby; |
|---|
| 13 | + $count = 'DISTINCT ' . $groupby; |
|---|
| 14 | + } else { |
|---|
| 15 | + $count = '*'; |
|---|
| 16 | + } |
|---|
| 17 | + |
|---|
| 18 | if ( !empty( $orderby ) ) |
|---|
| 19 | $orderby = 'ORDER BY ' . $orderby; |
|---|
| 20 | |
|---|
| 21 | - $found_rows = ''; |
|---|
| 22 | - if ( !$q['no_found_rows'] && !empty($limits) ) |
|---|
| 23 | - $found_rows = 'SQL_CALC_FOUND_ROWS'; |
|---|
| 24 | - |
|---|
| 25 | - $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
|---|
| 26 | + $this->request = " SELECT $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; |
|---|
| 27 | if ( !$q['suppress_filters'] ) |
|---|
| 28 | $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); |
|---|
| 29 | |
|---|
| 30 | @@ -2640,7 +2641,7 @@ |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | if ( !$q['no_found_rows'] && !empty($limits) ) { |
|---|
| 34 | - $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); |
|---|
| 35 | + $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( "SELECT COUNT($count) FROM $wpdb->posts $join WHERE 1=1 $where $orderby", &$this ) ); |
|---|
| 36 | $this->found_posts = $wpdb->get_var( $found_posts_query ); |
|---|
| 37 | $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); |
|---|
| 38 | $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); |
|---|