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)

    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.