Hey,
I’m using acf_form to create new and edit existing posts of CPT ‘discs’.
This is my code in functions.php:
// Create the frontend form
function my_pre_save_post( $post_id ) {
if ( $post_id != 'new' ) {
return $post_id;
}
$post = array(
'post_status' => 'draft',
'post_title' => $_POST['fields']['field_5479cd3485fcf'],
'post_type' => 'discs'
);
$post_id = wp_insert_post($post);
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
This is my code to add new ‘discs’ posts:
$args = array(
'post_id' => 'new',
'field_groups' => array(177, 100, 104, 111, 113, 136),
'field_el' => 'div',
'return' => home_url() . '/discs/#new-success',
'submit_value' => 'Create',
'updated_message' => 'Done.'
);
acf_form( $args );
And this is my code to edit existing ‘discs’ posts:
$args = array(
'post_id' => get_the_ID(),
'field_groups' => array(100, 104, 111, 113, 136),
'form' => true,
'return' => home_url() . '/discs/#edit-success',
'html_before_fields' => '',
'html_after_fields' => '',
'post_status' => 'draft',
'submit_value' => 'Update',
'updated_message' => 'Update done.'
);
acf_form( $args );
However, add new posts and edit existing posts works fine.
Additionally I want two things:
1) After editing a post, set the post_status to ‘draft’ or ‘pending’.
2) When creating a new post, get the value from input field (name / field_5479cd3485fcf) and set this as the new post_title.
I tried a lot but nothing worked for me.
Thanks for your help!