how to upload an image on ACF with update_field on wordpress how to upload an image on ACF with update_field on wordpress wordpress wordpress

how to upload an image on ACF with update_field on wordpress


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:

return array(    'pid' =>$pid,    'url' =>$file['url']);

With the following array:

return array(  'pid' =>$pid,  'url' =>$file['url'],  'file'=>$file,  'attach_id'=>$attach_id);

and then change

update_field('field_512e085a9372a',$att['url'],$watch);

with the following

update_field('field_512e085a9372a',$att['attach_id'],$watch);


should this line
if ( !is_wp_error( $id )) {
be
if ( !is_wp_error( $attach_id )) {


Check this plugin:

https://wordpress.org/plugins/acf-frontend-display/

  1. Create ACF form with frontendUploader field (plugin extention)
  2. Add your ACF form into post and with post admin panel use checkbox to view on front