Opened 12 years ago
Closed 12 years ago
#22213 closed defect (bug) (invalid)
split_the_query breaks posts_distinct filter
Reported by: | johnbillion | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4 |
Component: | Query | Keywords: | has-patch 2nd-opinion |
Focuses: | Cc: |
Description (last modified by )
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.
Attachments (1)
Change History (5)
Note: See
TracTickets for help on using
tickets.
Patch which grabs the ID fields from
$wpdb->get_results()
if there's a DISTINCT value in the query.