假设我正在查询两种post类型,如下所示:
$args = array(
'post_type' => array('post', 'another_post_type'),
'tax_query' => array(
array(
'taxonomy' => 'custom-taxonomy',
'field' => 'slug',
'terms' => 'test-slug',
)
)
);如果我将custom-taxonomy链接到another_post_type,我将如何运行此查询以使tax_query仅针对another_post_type帖子运行?基本上,我希望查询返回所有常规的post,但只返回类别为test-slug的another_post_type帖子。
这个是可能的吗?
发布于 2019-04-05 06:11:18
这似乎起作用了:
$args = array(
'post_type' => array('post', 'another_post_type'),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'custom-taxonomy',
'field' => 'slug',
'terms' => 'test-slug'
),
array(
'taxonomy' => 'category', # default post category
'operator' => 'EXISTS'
)
)
);https://stackoverflow.com/questions/55525108
复制相似问题