Marking future dated post as published

Use case:

I have a post type that relates to a music show. The ‘show time’ is grabbed through the post publish date which is set to some time in the future. I’ve found a function that takes future dated blog posts and leaves the date but marks the post as published on save but haven’t been able to figure how to customize it for a custom post type.

The function is below.

<?php
    function setup_future_hook() {
        // Replace native future_post function with replacement
        remove_action('future_post','show', '_future_post_hook');
        add_action('future_post', 'show', 'publish_future_post_now');
    }

    function publish_future_post_now($id) {
        // Set new post's post_status to "publish" rather than "future."
        wp_publish_post($id);
    }

    add_action('init', 'setup_future_hook');
?>

5

Awesome combining both the answers from Mike and Jan I came up with this which works only on the post type in question. We don’t need the conditional of show because the ‘future_show’ hook only grabs the post type of show and updates that.

<?php
    function setup_future_hook() {
        // Replace native future_post function with replacement
        remove_action('future_show','_future_post_hook');
        add_action('future_show','publish_future_post_now');
    }

    function publish_future_post_now($id) {
        wp_publish_post($id);
    }

    add_action('init', 'setup_future_hook');
?>

Leave a Comment