[wp-hackers] Grouping taxonomy queries
John Blackbourn
johnbillion+wp at gmail.com
Thu Aug 9 00:52:50 UTC 2012
On 8 August 2012 04:31, Scott Taylor <scott.c.taylor at mac.com> wrote:
> You have to do a join for every condition, so tax_query probably isn't the best mechanism. Here's how the query will end up:
>
> SELECT ID FROM wp_posts p
> INNER JOIN wp_term_relationships AS tt1 ON (p.ID = tt1.object_id) // for your IN condition *or* AND condition
> INNER JOIN wp_term_relationships AS tt2 ON (p.ID = tt2.object_id) // for your AND condition
> WHERE
> // IN condition *or* AND condition
> ( ( tt1.object_id IN ( $a_tt_id ) ) OR ( tt1.object_id IN ( $b_tt_id ) AND tt2.object_id IN ( $c_tt_id ) )
>
> // this isn't the whole query, you'll want to check post_status, etc
>
> So, if you can grab the term_taxonomy_ids you need first, you can do $wpdb->get_col with a query like above and then do a WP_Query with 'post__in' with the get_col result array
Thanks Scott, I suspected that would be the case!
John
More information about the wp-hackers
mailing list