Home › Forums › Front-end Issues › acf_form() always creates two posts › Reply To: acf_form() always creates two posts
With just ACF Pro installed on a default theme.
I added this to functions.php
function my_pre_save_post($post_id) {
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'draft' ,
'post_title' => 'test candidate',
'post_type' => 'candidates',
);
// insert the post
$post_id = wp_insert_post($post);
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
Then I put acf_form_head();
in my template file before get_header();
and I added this to the content are of the template file
$args = array(
'post_id' => 'new',
'submit_value' => 'Book',
'field_groups' => array(3304)
);
acf_form($args);
It uses a different field group but other than that everything is the same. I even set up the custom post type you’re using. Everything works as expected.
To figure out where the problem is you need to start removing things. Make sure only ACF Pro is installed and switch to on of the default WP 20XX themes. It could also be something in the theme you’re using.
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.