• How come I can’t display the loop of posts on a page with

    <?php if (have_posts()) : ?>
       <?php while (have_posts()) : ?>
          <?php the_post(); ?>
    
             <?php the_content(); ?>
    
       <?php endwhile; ?>
    <?php endif; ?>

    but I can with a WP_query?

    $the_query = new WP_Query( array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>5) ); ?>
    
    <?php if ( $the_query->have_posts() ) : ?>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    <?php the_content(); ?>
    
    <?php endwhile; ?>
    <?php wp_reset_postdata(); // reset the query  ?>
    <?php endif; ?>
  • The topic ‘displaying the loop with or without WP_query’ is closed to new replies.