Ticket #10964: simple_groupby_modified_simpler.10964.diff
File simple_groupby_modified_simpler.10964.diff, 1.6 KB (added by , 13 years ago) |
---|
-
wp-includes/query.php
2591 2591 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 2592 2592 } 2593 2593 2594 if ( ! empty($groupby) ) 2595 $groupby = 'GROUP BY ' . $groupby; 2594 if ( ! empty($groupby) ) { 2595 $groupby = 'GROUP BY ' . $groupby; 2596 $count = 'DISTINCT ' . $groupby; 2597 } else { 2598 $count = '*'; 2599 } 2600 2596 2601 if ( !empty( $orderby ) ) 2597 2602 $orderby = 'ORDER BY ' . $orderby; 2598 2603 2599 $found_rows = ''; 2600 if ( !$q['no_found_rows'] && !empty($limits) ) 2601 $found_rows = 'SQL_CALC_FOUND_ROWS'; 2602 2603 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2604 $this->request = " SELECT $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2604 2605 if ( !$q['suppress_filters'] ) 2605 2606 $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); 2606 2607 … … 2640 2641 } 2641 2642 2642 2643 if ( !$q['no_found_rows'] && !empty($limits) ) { 2643 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );2644 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( "SELECT COUNT($count) FROM $wpdb->posts $join WHERE 1=1 $where $orderby", &$this ) ); 2644 2645 $this->found_posts = $wpdb->get_var( $found_posts_query ); 2645 2646 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2646 2647 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);