• I wanted to display future posts and sticky posts on a homepage template. The posts are displaying as one, though. What am I doing wrong? Here is my code:

    <div id="top" class="left">
    <h1>Sticky Posts</h1>
    <?php
    // the query
    $query2 = new WP_Query( array( 'post__in' => get_option('sticky_posts') ) ); ?>
    
    <?php if ( $query2->have_posts() ) : ?>
    
      <!-- pagination here -->
    
      <!-- the loop -->
      <?php while ( $query2->have_posts() ) : $query2->the_post();  $do_not_duplicate = $post->ID; ?>
       <div class="sticky"> <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a></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; ?>
    
    </div>
    
    <div id="top" class="right">
    <h1>Upcoming Posts</h1>
    <?php
    // the query
    $query1 = new WP_Query( array( 'post_status' => 'future', 'post_type' => 'post', 'posts_per_page' => 5  ) ); ?>
    
    <?php if ( $query1->have_posts() ) : ?>
    
      <!-- pagination here -->
    
      <!-- the loop -->
      <?php while ( $query1->have_posts() ) : $query1->the_post();
     if( $post->ID == $do_not_duplicate ) continue; ?>
        <h2><?php the_title(); ?> <span>- <?php the_time('F j, Y'); ?></span></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)
  • Thread Starter Judia

    (@judia)

    Clarify: Sticky posts are displayed as future posts, even though they’re posted alright. Visa versa with future posts.

Viewing 1 replies (of 1 total)
  • The topic ‘Future & Sticky Posts Displaying At Once’ is closed to new replies.