[wp-trac] Re: [WordPress Trac] #3681: Lack of forced GROUP BY or DISTINCT in query.php causes duplicate posts when plugins JOIN on wp_posts.ID = wp_post2cat.post_id

WordPress Trac wp-trac at lists.automattic.com
Fri Jan 26 04:26:08 GMT 2007


#3681: Lack of forced GROUP BY or DISTINCT in query.php causes duplicate posts
when plugins JOIN on wp_posts.ID = wp_post2cat.post_id
---------------------+------------------------------------------------------
 Reporter:  ajd777   |        Owner:  anonymous
     Type:  defect   |       Status:  new      
 Priority:  high     |    Milestone:           
Component:  General  |      Version:  2.1      
 Severity:  major    |   Resolution:           
 Keywords:           |  
---------------------+------------------------------------------------------
Comment (by ajd777):

 Replying to [ticket:3681 ajd777]:
 > In version 2.0.x DISTINCT was automatically added to all queries that
 weren't in the admin panel (line 593 of classes.php). However, 2.1 took
 out this section and doesn't automatically us it or GROUP BY except when
 viewing single categories (lines 811 (808) and 845 (841) of query.php).
 >
 > This is an easy fix just add a default filter or force it inside the
 function to either use GROUP BY `ID` or DISTINCT by default.

 As a temporary fix for plugin authors:

 function force_groupby ( $groupby ) {
         if ( $groupby == '' ) {
                 return ' `ID`';
         }
 }

 add_filter('posts_groupby', force_groupby);

-- 
Ticket URL: <http://trac.wordpress.org/ticket/3681#comment:1>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list