我想显示提交了2个或更多自定义分类术语的帖子。例如,我想显示自定义帖子类型“分类”的帖子,并将其归档在Books和House terms下。
下面的代码显示了在术语中标记的帖子。我只想在两个术语中标记帖子:
$args = array(
\'posts_per_page\' => 10, // Number of posts per page
\'post_type\' => \'classifieds\', // Custom Post Type like Movies
\'tax_query\' => array(
array(
\'taxonomy\' => \'classifieds_tags\', //Custom Taxonomy Name like Genre
\'field\' => \'slug\',
\'terms\' => array(
\'books\', //Tags or Categories like Drama or Comedy
\'houses\'
)
)
)
);
SO网友:David
您需要将两个税务查询与和结合起来AND
关系:
$args = array(
\'posts_per_page\' => 10, // Number of posts per page
\'post_type\' => \'classifieds\', // Custom Post Type like Movies
\'tax_query\' => array(
\'relation\' => \'AND\'
array(
\'taxonomy\' => \'classifieds_tags\', //Custom Taxonomy Name like Genre
\'field\' => \'slug\',
\'terms\' => array(
\'books\' //Tags or Categories like Drama or Comedy
)
),
array(
\'taxonomy\' => \'classifieds_tags\', //Custom Taxonomy Name like Genre
\'field\' => \'slug\',
\'terms\' => array(
\'houses\'
)
),
)
);
SO网友:Simon
我认为您需要添加relation
参数:
$args = array(
\'posts_per_page\' => 10, // Number of posts per page
\'post_type\' => \'classifieds\', // Custom Post Type like Movies
\'tax_query\' => array(
array(
\'taxonomy\' => \'classifieds_tags\', //Custom Taxonomy Name like Genre
\'field\' => \'slug\',
\'relation\' => \'AND\',
\'terms\' => array(
\'books\', //Tags or Categories like Drama or Comedy
\'houses\'
)
)
)
);