Posted by & filed under Code, Wordpress.

This week I am wanting to show you something very useful. If you are like me you may do many posts and schedule them to be posted. What if you wanted to display your up and coming posts to the users so they know what is to come and when. Well you can very easily.

 

   1:  <?php
   2:  $my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
   3:  if ($my_query->have_posts()) {
   4:      while ($my_query->have_posts()) : $my_query->the_post(); ?>
   5:          <li><?php the_title(); ?> – <?php the_date(); ?></li>
   6:      <?php endwhile;
   7:  }
   8:  ?>

 

So what have we done? Well this is simple we have used the WP_Query class which allows us to get all the future posts and we have limited to 5, then we have done the simple loop that is the same as the one we always use.

Inside the while loop we can display them however, we want. I am just showing a very simple way of doing it.

Leave a Reply

  • (will not be published)