How to Publish a WordPress Post with a Future Date but Display Now

You may want to publish your WordPress post just right now but post date will be a future time. By default WordPress doesn’t have such option. Here I will show you a very simple trick to do this.
WordPress Clock
WordPress has an option to publish any post in a future date/time. It is called future-post/Scheduled-post. You can set future date/time for a post from the post edit panel just above the publish button. After setting up the post date with a future time the publish button will be changed into Schedule button. You may finish your posting by clicking on Schedule button. Your post will be saved for future publishing, post_type field will be set by ‘future‘ instead of ‘publish‘ . And it will not be displayed to visitors on your site fornt-end. WordPress displays which posts those have post_type=’publish’. You may manage your scheduled posts from dashboard by using my plugin “WP Scheduled Posts“. When your given future date will come then post will be published automatically and appeared to all. But if you want you publish your post immediately right now and post date will set as a future date, what to do then? WordPress doesn’t have any default solution for this situation. But WordPress is very flexible and customizable CMS, It gives us a lot of filter and action hooks to fire our custom function on any point of the script. I made a very simple PHP codes to have this feature with an WordPress blog. Put my following codes in your theme functions.php. I have updated my plugin “WP Scheduled Posts” by including this feature. You can use that plugin instead of editing functions.php.

<?php
function onetarek_prevent_future_type( $post_data ) {
if ( $post_data['post_status'] == 'future' && $post_data['post_type'] == 'post' )#Here I am checking post_type='post' , you may use different post type and if you want it for all post type then remove "&& $post_data['post_type'] == 'post'"
{
$post_data['post_status'] = 'publish';
}
return $post_data;
}
add_filter('wp_insert_post_data', 'onetarek_prevent_future_type');
remove_action('future_post', '_future_post_hook');
?>

These codes prevents to create post_type=’future’ and publish the post immediately though the post date set for a future time. WordPress will not to thing about post date on publishing. It force WordPress to publish the post with future timestamps.

6 Comments


  1. Hi,

    thank you for this post. Is it possible to have this feature only for specific post categories?

    So Maybe i have to put something for more in here?
    if ( $post_data[‘post_status’] == ‘future’ && $post_data[‘post_type’] == ‘post’ )

    Like $post_data[‘post_category’] == ‘specific category’

    Sorry i´m a Beginner 🙂

    Thank you!

    Reply

    1. Yes , you can do that. But in that case you have to add new parameter to the function, Here I am using one parameter but wp_insert_post_data hook sends to parameters to the callback function.
      https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data
      `post_category` is not exists in post_data array. That exists in the second parameter $postarr . So add new parameter to the callback function and check category in $postarr array.

      Reply

  2. Super helpful! Thanks so much for posting this.

    I’m using a custom post type for events and need to be able to show upcoming events, I didn’t want to have to start all over again and this is exactly what I needed!

    Reply

  3. Worked perfectly.

    I also needed to publish future events for an events calendar.

    Thank you!

    Reply

  4. I see an option saying “Show Publish Post Immediately Button” and I enabled it. However I didn’t see the “checkbox” or button appeared in my post editor. I am using WP 5.2.4

    Reply

  5. I’ve tried adding your code to my functions.php file as well as installing WP Scheduled Posts, nothing seems to work. I have all categories allowed, (although I want to specify one category) and type is posts. I’ve also tried a few other solutions from Stack Exchange with no luck. Something in my theme must be overriding, although I don’t see any settings to determine whether or not future posts are showing.

    There should be an event on the homepage that dated for May 16th.

    Help!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.