获取帖子类型和类别

时间:2015-10-27 15:36:53

标签: wordpress post categories

在我的首页(index.php)上,我想显示所有类型'事件'以及类别' main'类型' post'。我如何合并这两个条件?在我目前的代码中,我可以过滤两种帖子类型,但不能过滤类别' main'。

<?php global $wp_query; $args = array_merge( $wp_query->query, array( 'post_type' => array('post','event') ));
query_posts( $args ); ?>

1 个答案:

答案 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'
       ),
    )
);
?>