I'd like all new posts that are created via the admin interface to have a date set in the future. For example, if I'm creating a post now, I'd like it to default to "scheduled for tomorrow".

I found the hook that's called when a new post is created (auto-draft_post), and I can access the post date fine, and I can add a time to the new date in PHP. But when I set $post->post_date to something else, it does not update the new post with this value.

I've tried saving the post using wp_update_post as well as wp_insert_post, thinking that new posts are not saved to the database until they are auto-saved, but these functions only create an instant loop without ever updating or saving the post. Here's my code:

function pq_dateTest ($ID, $post) {

    // give a future date to the post (hard coded for testing)
    $post->post_date = '2027-06-09 09:15:37';

    // these will create endless loops, but will not update my post
    // wp_update_post($post);
    // wp_insert_post($post);
add_action ('auto-draft_post', 'pq_dateTest', 10, 3);

I've also tried to wp_schedule_single_event() to create the post as suggested here, but that also does not save my post.

What am I doing wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.