我有一个自定义帖子类型图片与自定义分类称为image_tag(它是像分类像分类)。这里有可能被使用的标记的一些例子:Wordpress tax_query“and”operator not as functional expected
Structure (id: 25)
- House (id: 56)
- Skyscraper
Nature
- Animal
- Plant (id: 41)
所以,我想通过与“和”运营商一起选择多个标签通过图像向下钻取。例如,查找所有照片工厂 s和house s。
$query_args = array(
'post_type' => 'image',
'tax_query' => array(
array(
'taxonomy' => 'image_tag',
'terms' => array(25, 41), // IDs of "structure" and "plant"
'operator' => 'and',
),
),
);
然后我没有得到任何结果:
$query_args = array(
'post_type' => 'image',
'tax_query' => array(
array(
'taxonomy' => 'image_tag',
'terms' => array(41, 56), // IDs of "plant" and "house"
'operator' => 'and',
),
),
);
这工作正常,当我尝试包括父词条,例如问题开始。我猜是因为我使用“和”运算符,Wordpress不包括“结构”术语的子代。有没有人有一个想法,我怎么能得到这个工作?
两个简单的问题: 1)只是为了确定。你能100%确认是否有应该退回的帖子? 2)你是否明确设置'include_children'为'true'?我相信那里至少有一个需要你这样做的错误(尽管它通常是默认的)。 – mrwweb
好的:1)是的,有一些帖子标有这两个词(或其中的孩子),2)是的,我也尝试过'include_children',可悲的是,似乎没有任何影响。 – dkeeling
很高兴知道。我的下一个猜测是@ hubert-popp的答案如下。我会尝试。 – mrwweb