WordPress.org

Make WordPress Core

Ticket #10964: simple_groupby_modified_simpler.10964.diff

File simple_groupby_modified_simpler.10964.diff, 1.6 KB (added by kawauso, 7 years ago)

Simplified version of simple_groupby_modified

  • wp-includes/query.php

     
    25912591                                $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
    25922592                }
    25932593
    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
    25962601                if ( !empty( $orderby ) )
    25972602                        $orderby = 'ORDER BY ' . $orderby;
    25982603
    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";
    26042605                if ( !$q['suppress_filters'] )
    26052606                        $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
    26062607
     
    26402641                }
    26412642
    26422643                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 ) );
    26442645                        $this->found_posts = $wpdb->get_var( $found_posts_query );
    26452646                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    26462647                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);