Skip to content
Advertisement

how to upload an image on ACF with update_field on wordpress

I have a form, which has an upload ($_FILES['watch_photo']) field.

I have looked around and came to put this function together.

It basically takes all relevant information so it is re-usable in the future, it will return an array of the $pid, and URL of the file, when it is done.

The problem is that ACF has not provided much information how to add images to it’s fields using update_field() http://www.advancedcustomfields.com/resources/functions/update_field/

JavaScript

and then I used the following code:

  • to create a post and then
  • upload then use my_update_attachment to process the image
  • and finally update the advanced custom field

The code:

JavaScript

What am I missing? any help would be greatly appreciated.

Advertisement

Answer

I had the same problem, you almost had it right, which helped me as well.

looked at ACF and the update_field accepts attachment ID as oppose to the the, pid or url

You can replace the return array:

JavaScript

With the following array:

JavaScript

and then change

JavaScript

with the following

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement