Last active
December 20, 2015 17:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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