Home › Forums › Front-end Issues › acf_form NOT creating new Post › Reply To: acf_form NOT creating new Post
I resolved my problem by changing the fields name from ['fields']
to ['acf']
The problem I am having now is editing a post. Here is the code in the functions.php file:
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
function my_pre_save_post( $post_id ) {
if( $post_id != 'new_post' ) {
return $post_id;
}
$post = array(
'post_status' => 'publish',
'post_title' => $_POST['acf']['field_54e6020d07a17'],
'post_content' => $_POST['acf']['field_54db8cd72d3c2'],
'post_type' => 'post' ,
);
$post_id = wp_insert_post( $post );
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
return $post_id;
}
Here is the acf_form on the Add Post page template:
acf_form( array(
'post_id' => 'new_post',
'fields' => array( 'field_54e6020d07a17', 'field_54db8cd72d3c2' ),
'updated_message' => 'Post Created'
));
Here is the acf_form on the Edit Post page template:
acf_form( array(
'post_id' => $_GET['post_id'],
'fields' => array( 'field_54e6020d07a17', 'field_54db8cd72d3c2' ),
'submit_value' => 'Update the post!'
));
Can anyone help me figure this one out? Thanks
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.