I've scheduled a custom post type to a future datetime. Now I won't that it will be published automatically, instead it should switch the status to draft.
We use this to pulish the webinars, so we can show upcoming webinars on the archive page. But if the time is coming to "publish" the webinar page, we would like to set it to draft. After the webinar we can edit the draft and insert the recording. This is the reason why we would like to change post_status from future to draft and NOT to publish.
We've tried the code below, but without success. It seems that this hook will be fired before the post ist stored to the database. But to hook wp_insert_post
or save_post_{$post->post_type}
won't give us the information about the old status, so that our function will only run if status is changed from future to publish.
Does anoybody has an idea? :-)
add_action( 'future_to_publish', array( $this, 'transitionFutureToPublish' ) );
public function transitionFutureToPublish( $post ) {
if ( ! empty( $post ) && $post->post_type == 'webinar' ) {
$post['post_status'] = 'draft';
wp_update_post( $post );
}
}