Support

Account

Home Forums ACF PRO ACF form submit fails to create a new WordPress post Reply To: ACF form submit fails to create a new WordPress post

  • I don’t know why it’s not working, but here are some problems with your code that may or may not be causing issues.

    Instead of using 2 acf_form() calls you should have only one and construct the field groups to be included before you call acf_form()

    
    $field_groups = array('group_5***d');
    if (current_user_can('activate_plugins')) {
      $field_groups[] = 'group_5***b';
    }
    
    // in your acf_form() call
    
    ....
    'field_groups' => $field_groups;
    ....
    

    Doing the above will also eliminate the need to call acf_form() with 'form' => false

    There is no post_category argument for acf_form()
    To set post values use the argument “new_post”

    
    .....
    'post_id' => 'new_post',
    'new_post' => array(
       // wp_insert_post() arguments here
       // https://developer.wordpress.org/reference/functions/wp_insert_post/
    ),
    

    With the above in place there will be no need to get the term and set it in your acf/pre_save_post filter. You should be able to set it to draft by supplying just the ID and status to wp_update_post()

    Another issue you might be having is not supplying a post title. Even if you do not supply a post title field in the form you should be setting something here and include it in the new_post argument array. WP has been know to have issue when a post is saved without a title.

    https://www.advancedcustomfields.com/resources/acf_form/