回答您的第二个问题-是的,这是可能的,您可以使用tax\\u query进行查询,例如,此查询将获取所有具有“flowers”分类法和“colors”分类法任何术语的帖子:
$query = new WP_Query( array(
\'post_type\' => \'custom-post\',
\'posts_per_page\' => 5,
\'order\' => \'DESC\',
\'tax_query\' => array(
\'relation\' => \'AND\', // it is also possible to use OR
array(
\'taxonomy\' => \'flowers\',
\'operator\' => \'EXISTS\'
),
array(
\'taxonomy\' => \'colors\',
\'operator\' => \'EXISTS\'
)
)
) );
第二个查询将获取所有包含“flowers”分类法中术语,但不包含“colors”分类法中术语的帖子:
$query = new WP_Query( array(
\'post_type\' => \'custom-post\',
\'posts_per_page\' => 5,
\'order\' => \'DESC\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'flowers\',
\'operator\' => \'EXISTS\'
),
array(
\'taxonomy\' => \'colors\',
\'operator\' => \'NOT EXISTS\' // <-- Take a look at this operator
)
)
) );
代码未经测试
这里还有文档的链接,请查看如何使用WP\\U查询https://developer.wordpress.org/reference/classes/wp_query/#standard-loop
以及WP\\U Tax\\U查询https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters