自定义帖子查询被覆盖 - 显示标准帖子

时间:2017-02-13 02:38:34

标签: wordpress custom-post-type

被这一个难倒......有些东西似乎干扰了我在页面模板上的wp_query。该查询适用于自定义帖子类型,但它会显示标准帖子,如果我回显查询,则看起来它已被重置。另一方面,query_posts函数与相同的$ args一起工作正常。

我的页面模板代码:

    <?php 
    $args = ['post-type' => 'electives', 'category' => 'esl', 'post-status' => 'publish']; 
    $the_query = new WP_Query( $args ); 
?> 

<?php if ( $the_query->have_posts() ) : ?>

    <!-- pagination here -->

    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <!-- end of the loop -->

    <!-- pagination here -->
    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

<?php endif; ?>

但这是传递给页面的请求:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 10

0 个答案:

没有答案