Skip to content

Instantly share code, notes, and snippets.

@gopperman
Last active December 20, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gopperman/6166280 to your computer and use it in GitHub Desktop.
Save gopperman/6166280 to your computer and use it in GitHub Desktop.
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