我有个问题category__in
当我执行WP\\U查询时。
$query_args = array(
\'post_type\' => \'posts\',
\'nopaging\' => true,
);
$categories = array(1,8); // If I use this, I get 3 posts
$categories = array(8, 1); // If I use this, I get 2 posts
$query_args[\'category__in\'] = $categories;
$query = new WP_Query($query_args);
显然,我传递“array(1,8)”时得到的结果与传递“array(8,1)”时得到的结果不同。
订单重要吗???还是这是一只虫子??
UPDATE
这是本案的请求
array(1,8)
string(571) "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) LEFT JOIN wp_term_relationships AS tt2 ON (wp_posts.ID = tt2.object_id) WHERE 1=1 AND (
wp_term_relationships.term_taxonomy_id IN (1)
AND
tt1.term_taxonomy_id IN (1)
AND
tt2.term_taxonomy_id IN (1,8)
) AND wp_posts.post_type = \'post\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC "
对于
array(8,1)
string(571) "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) LEFT JOIN wp_term_relationships AS tt2 ON (wp_posts.ID = tt2.object_id) WHERE 1=1 AND (
wp_term_relationships.term_taxonomy_id IN (8)
AND
tt1.term_taxonomy_id IN (8)
AND
tt2.term_taxonomy_id IN (1,8)
) AND wp_posts.post_type = \'post\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC "
SO网友:Enrique Moreno Tent
我用下面的方法解决了
$query_args[\'tax_query\'] = array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'category\',
\'field\' => \'id\',
\'terms\' => $categories,
),
);
显然,我不得不明确地说,我在过滤分类法中的“类别”。多亏了@birgire的评论,我才明白这一点。谢谢你,伙计!
Update
作为请愿书,以下是请求:
SELECT wp_posts.*
FROM wp_posts LEFT JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE 1=1 AND (wp_term_relationships.term_taxonomy_id IN (1,8))
AND wp_posts.post_type = \'post\'
AND (wp_posts.post_status = \'publish\'
OR wp_posts.post_status = \'private\')
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC