Ticket #2604: remove_distinct.diff

File remove_distinct.diff, 1.7 kB (added by ryan, 3 years ago)

Remove DISTINCT from main post query

  • wp-includes/query.php

    old new  
    505505                $result = ''; 
    506506                $where = ''; 
    507507                $limits = ''; 
    508                 $distinct = ''; 
    509508                $join = ''; 
    510509 
    511510                if ( !isset($q['post_type']) ) 
     
    822821                                $q['orderby'] = 'post_date '.$q['order']; 
    823822                } 
    824823 
    825                 //$now = gmdate('Y-m-d H:i:59'); 
    826                  
    827                 //only select past-dated posts, except if a logged in user is viewing a single: then, if they 
    828                 //can edit the post, we let them through 
    829                 //if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) { 
    830                 //      $where .= " AND post_date_gmt <= '$now'"; 
    831                 //      $distinct = 'DISTINCT'; 
    832                 //} 
    833  
    834824                if ( $this->is_attachment ) { 
    835825                        $where .= ' AND (post_type = "attachment")'; 
    836826                } elseif ($this->is_page) { 
     
    842832 
    843833                        if ( is_admin() ) 
    844834                                $where .= " OR post_status = 'future' OR post_status = 'draft'"; 
    845                         else 
    846                                 $distinct = 'DISTINCT'; 
    847835         
    848836                        if ( is_user_logged_in() ) 
    849837                                $where .= " OR post_author = $user_ID AND post_status = 'private'))"; 
     
    888876                $groupby = apply_filters('posts_groupby', $groupby); 
    889877                $join = apply_filters('posts_join_paged', $join); 
    890878                $orderby = apply_filters('posts_orderby', $q['orderby']);  
    891                 $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits"; 
     879                $request = " SELECT * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits"; 
    892880                $this->request = apply_filters('posts_request', $request); 
    893881 
    894882                $this->posts = $wpdb->get_results($this->request);