• I have 2 queries on 1 page and they’re showing the same posts, but the second query is turning in different posts including the posts of the first query. I’ve rearranged the code and done everything I could to stop it from happening, but I don’t know what’s wrong. Does anyone know what I’m doing wrong?

    here is my code:

    <div id="top" class="left">
    <h1>Sticky Posts</h1>
    <?php $query = new WP_Query( array( 'post_in' => get_option( 'sticky_posts') ) ); ?>
    
    <?php if ( $query->have_posts() ) : ?>
    
      <!-- pagination here -->
    
      <!-- the loop -->
      <?php while ( $query->have_posts() ) : $query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
      <?php endwhile; ?>
      <!-- end of the loop -->
    
      <!-- pagination here -->
    <?php else:  ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
      <?php wp_reset_postdata(); ?>
    
    </div>
    
    <div id="top" class="right">
    <?php
    // the query
    $the_query = new WP_Query( array( 'post_status' => 'future', 'post_type' => 'post', 'order' => 'DESC'  ) ); ?>
    
    <?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; ?>
    </div>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Problem with 2 Queries on 1 Page’ is closed to new replies.