Display Future Posts in Your WordPress Theme
Today I want to focus on a very interesting feature of WordPress – the timestamp of a post or how to set a post on schedule and – and what else can we do with future posts. Learn how to run your blog on autopilot.
Maybe this happened to you once
All of a sudden you have a lot of inspiration and ideas for posts on your blog. Your head is full with first class content
and you want to write 5 posts… one after another. But since we all know that publishing all these posts at once is a waste of energy, we decide to spread the new content across several days or even weeks.
Or maybe you go on vacation for four weeks (lucky you!) but you want to keep offering your ‘Friday Web Design Blog Review’.
Wouldn’t it be nice to run your blog on autopilot?
To set a post on schedule to be publihed on a certain date at a certain hour is quite easy. In the write post panel in the right sidebar you’ll see the ‘Publish Status’ box. Under ‘Keep this post private’ it says ‘Publish immediately’. Click on ‘Edit’ next to it.

A form opens up where you can change the timestamp of the post. Here you can set the exact date and hour when you want you post to be published. If you choose a future date your post will appear as scheduled in the manage posts overview.
Your blog runs on autopilot now!
What else can we do with this timestamp feature?
Now we know that we can save posts with a future date. But can we display them on our blog? Yes, we can. And because we can, I had the idea of building an Upcoming Events list like in the example below.

In my example we have a list with upcoming events and onther list below with previous events. Please note that the upcoming events list is in chronological (ascending) order. Once a future event date passes, it will automatically change to the Previous Events list.
First I want to show you how to call the previous events. Since these are normal posts, we just make a normal query for posts of a certain category – here events. If there are no previous events, the phrase No previous Events will be displayed.
<h4>Previous Events</h4>
<?php
$my_query = new WP_Query('category_name=events');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No previous Events'); ?></li>
</ul>
<?php endif; ?>Now we try to display the future posts just adding some arguments to the post query.
<h4>Upcoming Events</h4>
<?php
$my_query = new WP_Query('category_name=events&post_status=future&order=ASC');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No upcoming Events'); ?></li>
</ul>
<?php endif; ?>Please note that the WP_Query function now only asks for posts with post_status future and will display them in an ascending (chronological) order. If there are no upcoming events, the phrase No upcoming Events will be displayed.
Put it all together
In my example I want to display the upcoming events on the top and the previous events below. So here you get the complete code:
<h4>Upcoming Events</h4>
<?php
$my_query = new WP_Query('category_name=events&post_status=future&order=ASC');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No upcoming Events'); ?></li>
</ul>
<?php endif; ?>
<h4>Previous Events</h4>
<?php
$my_query = new WP_Query('category_name=events');
?>
<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
?>
<ul>
<li>
<strong><?php the_time('l, F jS, Y') ?>:</strong><br />
<?php the_title(); ?>
</li>
</ul>
<?php endwhile; else: ?>
<ul>
<li><?php _e('No previous Events'); ?></li>
</ul>
<?php endif; ?>Now just style the list to your liking and you have a nice automatic events list divided into upcoming and previous event.
24 Kommentare
4 Trackbacks
- AfiÅŸarea titlurilor articolelor viitoare în WordPress | Moldova CreÅŸtină - [...] anunÅ£ pe cititori despre titlurile acelor articole. Azi am găsit pe portalul www.webdemar.com o soluÅ£ie foarte bună pe care ...
- Afficher les futurs articles de votre blog Wordpress | Geekeries.fr - Astuces Wordpress, Actualités High-Tech, Plugins Wordpress, Apple, Windows - [...] Cette petite fonction est très pratique puisqu’elle vous permettra de donner un avant goût de vos prochains articles de ...
- Managementul comentariilor | Bluarto - Zâmbeşte de vorbă bună! - [...] Programarea apariţiei articolelor (autopilot, nene!) poate fi aplicată şi comentariilor. Astfel, profitând de un articol controversat, cu, să spunem, ...
- Display Future Posts in Your WordPress Theme | webdemar.com - [...] Go here to see the original: Display Future Posts in Your WordPress Theme | webdemar.com [...]


11. Oktober 2008
Thanks dude! The events list is a great use of this Wordpress feature!
16. Oktober 2008
Great article. I could really use the information here. I had been looking for this sort of thing for a while. Thanks
20. Oktober 2008
Great tip! I was checking out your themes (which are gorgeous, by the way), when I found this post. Very timely. I put it to work right away on my own blogs, then I published a similar tip on my site, with a link back here, of course. I didn’t go into the depth that you did. I figured it people wanted to go that deep, they could learn that here. Nice job.
24. Oktober 2008
What a great tutorial – I’ve been looking for something like this for a year now – thanks!
28. Oktober 2008
I don’t want to repeat what other have said but this is a great article. I would have to try this.
3. November 2008
Hmm, looks mighty similar to the code posted here back in June …
http://www.keithmillington.co.uk/wordpress/?p=22
29. November 2008
I love this idea. I am going to use your idea for my membership site (I created using wordpress).
19. Dezember 2008
Thank you very much. I was looking for a long time after such an advice and I already use this on my romanian part of the blog and also, wrote an article in Romanian so that people may use it. Thank you very much and may God bless you with a blessed Christmas and with the gift of Eternal Life through faith in our Lord Jesus Christ.
21. Dezember 2008
Wow, never thought/knew of “post_status=future” to display future scheduled posts. This is a great tip!
20. Januar 2009
Thanks so much! This is such a great function
20. Januar 2009
@Ben T:
Happy you like it
30. Januar 2009
Great code! thanks.
At first, mine not work until I remove the category=event ^^ and then I develop it into a plugin with some advanced feature
http://wordpress.org/extend/plugins/upcoming-posts/
enjoy!
27. Februar 2009
Great use of post status! I like the simplicity of idea rather than adding massive calendar plugin
20. April 2009
I am using an upcoming posts list in my footer and the text formatting is not the same as the rest of my themes for some reason…how do I hcange it to look like the rest of the footer’s font size/color? And how do I make each future post list as a new list item?
Thanks for the help,
Sabrina
20. April 2009
@Sabrina:
At the moment you have a php error in your footer. To help you fix your problem I need to see it live.
30. April 2009
Excellent tip there, there’s nothing better than scheduling posts in advance, especailly with news. It’s worth spending a good few hours to write some posts at the start of the month and spread them out throughout the month.
28. Juli 2009
Alternatively you can opt on using the following plugin which does just that: http://wordpress.org/extend/plugins/display-scheduled-posts/
28. September 2009
Funktioniert gut, nur die Standartsuche von WordPress sucht nicht in Artikeln mit zukünftigen Datum. Das ist doof. Das Plugin “The Future Is Now” ermöglicht ebenfalls im Loop future Posts anzuzeigen, diese werden aber auch mit der Suchfunktion gefunden. Naürlich ist eine Lösung ohne Plugin immer vorzuziehen. Vielleicht kannst Du das Problem ja noch lösen!?
30. September 2009
Hi! Great tips!
Wonder if there is any way to have the future events posted in the feed as well? Today I only see the previous..
Big thanx for any ideas to solve the problem
/Emma
20. November 2009
You need to add &posts_per_page=-1 if you want to show all future events. Otherwise it will limit it to whatever your normal page count is.
24. November 2009
Dude! Sweet!
5. Dezember 2009
I have the same problem on future posts not displaying on single post template(single.php) but I created my own plugin to fix this. NO hacks and NO need to edit your templates. Just install it and it solves the problem.
Check: http://wordpress.org/extend/plugins/show-future-posts-on-single-post/
Running example is at http://www.FredRadio.com
20. Dezember 2009
Thank you very much for the code. I worked a lot of work.
Translate Turkish: Kodlar için çok teÅŸekkürler. Çok iÅŸime yaradı.
10. März 2010
Thank you. I however ran into a problem I can’t solve. I can only access future posts when logged in. When a guest user comes he can only access Past posts, can see the list of future posts but the future posts appear as 404 to him. Any suggestions?