Actually, it does this with cat, too! I decided to see if there was an issue with just giving the query “category__and” without a “cat” first being set. So I hardcoded my $args to include
$args['cat'] = "157";
$args['category__and'] = "141";
Here’s also the output of all of my $args values:
post_status: publish
posts_per_page: 20
paged: 1
meta_key: support-file-url
orderby: post_date,meta_value
order: DESC,ASC
cat: 157
category__and: 141
Here’s the SQL that query_posts($args) gives me:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) JOIN wp_icl_translations t ON wp_posts.ID = t.element_id AND t.element_type IN ('post_post','post_page') JOIN wp_icl_languages l ON t.language_code=l.code AND l.active=1 WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (156) AND ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (140) AND object_id = wp_posts.ID ) = 1 ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_key = 'support-file-url' ) AND t.language_code='en' GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 20
See the “wp_term_relationships.term_taxonomy_id IN (156)” and “term_taxonomy_id IN (140)”???? Why is it offsetting the input category values by one? I also double-checked the database to make sure that the IDs corresponded to the desired categories… and I definitely want to be searching for 157 and 141, not 156 and 140.
Definitely seems like something is wrong here.
I posted more code here: https://gist.github.com/relish27/5237317
I also just tried copying and pasting the “category__and” code from the WP
query_posts page: http://codex.wordpress.org/Function_Reference/query_posts
But with the IDs changed in the array:
query_posts( array( 'category__and' => array(157,158,144), 'posts_per_page' => 2, 'orderby' => 'title', 'order' => 'DESC' ) );
It still returns “WHERE term_taxonomy_id IN (143,156,157)” in the SQL! Am I misunderstanding how this works? I don’t understand where this offset is coming from…