Custom queries selecting events by category result in incorrect SQL
-
Hi,
Tested with The Events Calendar 6.0.5.
We have a plugin which supports listing events in The Events Calendar. When querying by category (tribe_events_cat) the resulting SQL is incorrect when selecting events in more than one category.
For example, the following query which should display events from 3 categories:
Array ( [post_type] => tribe_events [post_status] => publish [tax_query] => Array ( [0] => Array ( [taxonomy] => tribe_events_cat [terms] => Array ( [0] => conferences // ID: 184 [1] => meetups // ID: 183 [2] => expos // ID: 182 ) [operator] => IN [field] => slug ) ) [order] => DESC [orderby] => date [no_found_rows] => 1 [posts_per_page] => 10 [offset] => 0 )
Will produce this SQL:
SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id) JOIN wp_tec_occurrences ON wp_posts.ID = wp_tec_occurrences.post_id WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (182,183,184) AND tt1.term_taxonomy_id IN (184) ) AND wp_posts.post_type = 'tribe_events' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_tec_occurrences.occurrence_id ORDER BY wp_posts.post_date DESC LIMIT 0, 10
The first check on
term_taxonomy_id
is correct and built by WordPress from the supplied args, but the second check –tt1.term_taxonomy_id IN (184)
– is incorrect as it will limit the results to just the first category.
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Custom queries selecting events by category result in incorrect SQL’ is closed to new replies.