Home Forums Front-end Issues Reassign random Post ID with actual Post ID for new post Reply To: Reassign random Post ID with actual Post ID for new post

  • Thank you for getting back to me. Simply put, I already have a custom form and I am calling the file upload field by calling

            'post_id' => 'new',
            'form' => false,
            'field_groups' => array( 30 )

    As you can see, I am not calling the whole form (<form> tag and submit button), only the fields

    'form' => false,

    So I can’t use ‘acf/save_post’ because it won’t be triggered. It’s because my custom form uses AJAX to save the data calling POST via jQuery. So I use the following action to save ACF fields (I’ve simplified the field name)

    my_save_post($post_ID) {
        update_field('field_text', $_POST['field_text'], $post_ID);
        update_field('field_file', $_POST['field_file'], $post_ID);
    add_action('save_post', 'my_save_post');

    In this case, the field_text is saved, but not field_file because when the file information is inserted as attachment, it doesn’t save the “parent_post” ID correctly and becomes an orphan. And these 3 postmeta rows aren’t created either

    META_KEY                     META_VALUE
    _uploaded_file               field_689b0ed7249ab
    uploaded_file                345
    _edit_lock                   1383884182:1

    which are created normally if I upload a file when editing a post from the frontend if post_id is assigned.

    Thank you!