WordPress.org

Make WordPress Core

Ticket #10964: simple_groupby_modified.10964.diff

File simple_groupby_modified.10964.diff, 1.7 KB (added by prettyboymp, 7 years ago)
  • wp-includes/query.php

     
    25862586                }
    25872587
    25882588                if ( ! empty($groupby) )
    2589                         $groupby = 'GROUP BY ' . $groupby;
     2589                        $thegroupby = 'GROUP BY ' . $groupby;
    25902590                if ( !empty( $orderby ) )
    25912591                        $orderby = 'ORDER BY ' . $orderby;
    25922592
    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";
    25982594                if ( !$q['suppress_filters'] )
    25992595                        $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
    26002596
     
    26342630                }
    26352631
    26362632                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                        }
    26382638                        $this->found_posts = $wpdb->get_var( $found_posts_query );
    26392639                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    26402640                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);