Wordpress WP_查询不工作或不显示帖子内容

Wordpress WP_查询不工作或不显示帖子内容,wordpress,Wordpress,我是WordPress开发的新手,一直在关注一些在线的tut和阅读文档,但是我的WP_查询仍然没有显示任何内容,当我向循环中添加一个else时,会显示else条件。我已经创建了试图从数据库中提取的页面,我做错了什么?下面是代码: <section id="home"> <?php $query = new WP_Query( array( 'pagename' => 'home' ) );

我是WordPress开发的新手,一直在关注一些在线的tut和阅读文档,但是我的WP_查询仍然没有显示任何内容,当我向循环中添加一个else时,会显示else条件。我已经创建了试图从数据库中提取的页面,我做错了什么?下面是代码:

<section id="home">
               <?php
               $query = new WP_Query( array( 'pagename' => 'home' ) );
               if ($query->have_post() ) {
                 while ($query->have_posts() ){
                   $query->the_post();
                   echo '<div class="entry-content">';
                   the_content();
                   echo '</div>';
                 }
               }
               wp_reset_postdata();
                ?>
             </section>

只需更改

$query->have_post()


使用以下代码显示内容

$args=array(
    'post_type' => 'post'

);
$the_query = null;
// the query
$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>
        <div class="entry-content"><?php the_content(); ?></div>
    <?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; ?>
$args=array(
“职位类型”=>“职位”
);
$the_query=null;
//询问
$thew_query=newwp_query($args);?>


非常感谢您下次让我好好看看我的代码
$args=array(
    'post_type' => 'post'

);
$the_query = null;
// the query
$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>
        <div class="entry-content"><?php the_content(); ?></div>
    <?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; ?>