I have a question, how could I save the post as a “draft” after editing it? My code below doesn’t seem to work, the post still goes as published after I edit it in the frontend.
acf_form(array(
'post_id' => get_the_ID(),
'post_title' => true,
'return' => '%post_url%',
'new_post' => array(
'post_type' => 'event',
'post_status' => 'draft',
),
'submit_value' => 'Update event'));
Thanks.
Since you are not creating a new post but are updating an existing post you can’t use the new_post
argument to make the changes.
What you need to do is create an acf/pre_save_post filter https://www.advancedcustomfields.com/resources/acf-pre_save_post/, this is a filter that is run during the save action for acf_form().
In your filter you’ll need to update the status of the post
add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1);
function my_pre_save_post($post_id) {
// test to make sure this is front end and the right post type
// just in case
if (is_admin() || get_post_type($post_id) != 'your-post-type') {
return $post_id;
}
$args = array(
'ID' => $post_id,
'post_status' => 'draft'
);
wp_update_post($args);
return $post_id;
}