WordPress循环不尊重帖子状态

时间:2015-01-09 14:59:23

标签: php wordpress wp-query

我有一系列循环吐出“事件”自定义帖子类型,我只想用post_status“发布”来提取帖子。我在我的wp_query数组中添加了'publish'的post_status,但它似乎不起作用。我仍然有预定的帖子出现。

<?php
          $args_hotel_feature = array(
            'post_type' => 'event',
            'post_status' => 'publish',
            'posts_per_page' => 2,
            'meta_key' => '_expiration_date',
            'orderby' => 'meta_value',
            'order' => 'ASC',
              array(
                'key' => '_expiration_date', 
                'value' => date("m-d-Y"), 
                'compare' => '>=', 
                'type' => 'NUMERIC,' 
              ),
            'tax_query' => array(
                  array(
                        'taxonomy' => 'EventCategory',
                        'terms' => 'hotel-feature',
                        'field' => 'slug',
                  )
              ),
          );

          $wp_query4 = new WP_Query($args_hotel_feature);
          if($wp_query4->have_posts()) :
             while($wp_query4->have_posts()) :
              $wp_query4->the_post();
            ?>

其他人遇到过这个问题吗?

2 个答案:

答案 0 :(得分:0)

使用meta_query

$args_hotel_feature = array(
    'post_type' => 'event',
    'post_status' => 'publish',
    'posts_per_page' => 2,
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'meta_query' => array(
          array(
                'key' => '_expiration_date', 
                'value' => date("m-d-Y"), 
                'compare' => '>=', 
                'type' => 'NUMERIC,' 
          ) 
      ),
    'tax_query' => array(
          array(
                'taxonomy' => 'EventCategory',
                'terms' => 'hotel-feature',
                'field' => 'slug',
          )
      ),
  );

答案 1 :(得分:0)

原来查询很好,但是,过期后插件“帖子过期日期”会破坏post_staus。改为使用“Post Expirator”。

相关问题