在我的首页(index.php)上,我想显示所有类型'事件'以及类别' main'类型' post'。我如何合并这两个条件?在我目前的代码中,我可以过滤两种帖子类型,但不能过滤类别' main'。
<?php global $wp_query; $args = array_merge( $wp_query->query, array( 'post_type' => array('post','event') ));
query_posts( $args ); ?>
答案 0 :(得分:1)
只需将$ args更改为:
<?php
$args = array(
'post_type' => array('post','event'),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'terms' => 'main',
'field' => 'slug'
),
array(
'taxonomy' => 'event_tag', // this needs to be whatever custom taxonomy you have declared for your custom post type.
'terms' => 'main',
'field' => 'slug'
),
)
);
?>