Create a gist now

Instantly share code, notes, and snippets.

These Wordpress filters demonstrate two methods to publish (and view) posts in the future. Great for events, etc.
add_filter( 'wp_insert_post_data', 'publish_future' );
/* Avoid publishing posts as 'future' in the first place.
function publish_future( $data ) {
if ( $data['post_status'] == 'future' && $data['post_type'] == 'post' )
$data['post_status'] = 'publish';
return $data;
/* Show future posts even if they aren't published - maintains 'future' post_status */
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;
add_filter('the_posts', 'show_future_posts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment