[英]WP_Query to get posts for two different taxonomies using 'OR'
我想获得两种不同分类法的帖子。
我想列出职位只有那些帖子要么有标签longform
或 post_format
是键入link
。
我尝试过下面的代码,但它不起作用:
$query = new WP_Query(array(
'relation' => 'OR',
'posts_per_page' => 2,
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'link' ) // Single terms as string - multiple as array
),
array(
'taxonomy' => 'Tag',
'field' => 'id',
'tag__in' => array('16') // 16 is the code for tag longform
)
));
$terms = array('link');
$tax = array(16)
$args = array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => $terms,
),
array(
'taxonomy' => 'space',
'field' => 'id',
'tag__in' => $tax,
),
),
'posts_per_page' => 2
);
$the_query = new WP_Query( $args );
这应该工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.