Support

Account

Home Forums Front-end Issues get attachment ID after upload file via acf form

Solved

get attachment ID after upload file via acf form

  • Hello, first off: great plugin!

    Here is my issue:
    I have a front-end form to create a user and pass the form infos to it.
    The only struggle I have is with the image-file I want to pass to an image-field.

    Usually I would use something like $_FILES['my_image'] in a wp_handle_upload() function to get the attachment ID after it’s uploaded. But $_POST['acf']['field_5819d5e12d2d0'] gives me an error “Warning: Illegal string offset ‘size'” and $_FILES['acf']['field_5819d5e12d2d0'] gives “Notice: Undefined index: field_5819d5e12d2d0”.

    Even without any extra function, the file is still uploading to the media library. So is there a way to get the attachment ID of the file after it’s uploaded? Some value that is returned after the upload?

  • if field_5819d5e12d2d0 is the field key of the image field then the value of $_POST['acf']['field_5819d5e12d2d0'] is the attachment ID.

  • Hello John, thanks for your hint.

    After I read your answer, I realized that I tried to get the attachment ID in a pre_save_post action while the files wasn’t uploaded at this point.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘get attachment ID after upload file via acf form’ is closed to new replies.