[wp-trac] [WordPress Trac] #22213: split_the_query breaks posts_distinct filter

WordPress Trac noreply at wordpress.org
Wed Oct 17 13:05:30 UTC 2012


#22213: split_the_query breaks posts_distinct filter
-----------------------------+--------------------------
 Reporter:  johnbillion      |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Query
  Version:  3.4              |   Severity:  normal
 Keywords:                   |
-----------------------------+--------------------------
 If you add a DISTINCT value to a query using the `posts_distinct` filter
 then the functionality which splits a query (#18536) breaks because the
 values from your DISTINCT field are used instead of the ID field.

 Example:

 {{{
 add_filter( 'posts_distinct', function( $val ) {
         return 'DISTINCT post_author as pa, ';
 } );

 When the split query runs it uses `$wpdb->get_col()` which will return the
 DISTINCT field values we asked for instead of the ID fields. In the
 example above we get an array of post author IDs instead of post IDs.

 To get around this problem the split query had to be disabled for this
 request with the `split_the_query` filter.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22213>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list