Ticket #10964: simple_groupby_modified.10964.diff
File simple_groupby_modified.10964.diff, 1.7 KB (added by , 13 years ago) |
---|
-
wp-includes/query.php
2586 2586 } 2587 2587 2588 2588 if ( ! empty($groupby) ) 2589 $ groupby = 'GROUP BY ' . $groupby;2589 $thegroupby = 'GROUP BY ' . $groupby; 2590 2590 if ( !empty( $orderby ) ) 2591 2591 $orderby = 'ORDER BY ' . $orderby; 2592 2592 2593 $found_rows = ''; 2594 if ( !$q['no_found_rows'] && !empty($limits) ) 2595 $found_rows = 'SQL_CALC_FOUND_ROWS'; 2596 2597 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2593 $this->request = " SELECT $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $thegroupby $orderby $limits"; 2598 2594 if ( !$q['suppress_filters'] ) 2599 2595 $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); 2600 2596 … … 2634 2630 } 2635 2631 2636 2632 if ( !$q['no_found_rows'] && !empty($limits) ) { 2637 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); 2633 if( !empty($groupby) ) { 2634 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( " SELECT COUNT(distinct $groupby) FROM $wpdb->posts $join WHERE 1=1 $where $orderby", &$this ) ); 2635 } else { 2636 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( " SELECT COUNT(*) FROM $wpdb->posts $join WHERE 1=1 $where $orderby", &$this ) ); 2637 } 2638 2638 $this->found_posts = $wpdb->get_var( $found_posts_query ); 2639 2639 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2640 2640 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);