1
OCT 09

Show future posts in WP

Here is a code snippet I’ve made with the help of someone on the WP forums. I’ve also made a website which acts as a calender/overview for future posts by users.
A while later I will publish it as a plug-in which does the same trick.

add_filter('the_posts', 'show_future_posts');

function show_future_posts($posts)
{
 global $wp_query, $wpdb;

 if(is_single() && $wp_query->post_count == 0)
 {
  $posts = $wpdb->get_results($wp_query->request);
 }

 return $posts;
}

This code allows to show any future post on a post view page only, so your visitors can access a future post pages only if they have a direct link. As you understand you can set any condition instead of is_single, even you can remove any conditions and show future posts everywhere on your website.

Tags: ,

Leave a comment


This entry was posted by and on Thursday, October 1st, 2009 at 00:11 and is filed under Snippets, WordPress.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.