public
Last active

These Wordpress filters demonstrate two methods to publish (and view) posts in the future. Great for events, etc.

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.