Custom date changer post_date => future – missed schedule error

WordPress has this functionality: by setting the publication date to the future in the WordPress ‘publish’ box, the post will be given ‘future’ status and will be scheduled to publish for that date.

My guess is that the problem arises because you haven’t set the GMT time – which is what the WordPress uses to schedule the publications. Or otherwise you’ve hooked in after the scheduling has been done.

The ‘easy’ way (but leaves you with two ‘publish date meatboxes’ – which from a UI point of view is not great).

Keep in mind that WP expects the date in the Y-m-d H:i:s format

add_action('save_post', 'wpse50448_schedule_sermon');

function wpse50448_schedule_sermon($post_id) {

    //Perform checks, nonces etc

    $date="";//set date
    $date_gmt="";//set date in GMT (UTC)

    // unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'wpse50448_schedule_sermon');

    // update the post, which calls save_post again
    wp_update_post(array('ID' => $post_id, 'post_date' => $date,'post_date_gmt' => $date_gmt));

    // re-hook this function
    add_action('save_post', 'wpse50448_schedule_sermon');
}

This should work, but is not tested!

Alternative

Alternatively you can de-regester the publish metabox, and re-register it with exactly the same mark-up (but with some ID tags changed so WP’s javascript ignores it, and then apply your own javascript to it). From a UI point of view this much better, but a bit more involved.

The first part is outlined in this post for another metabox.