I want to make it so that when a user uploads an image on the front end form, it will not only save their image in an array, but it will also automatically assign the URL of the image as a separate Text field.
To demonstrate what I’m trying to do, it would look something like this where ‘user_image’ is an Image field stored as an array and ‘image_url’ is a Text field.
$user_id = get_current_user_id();
$imagearray = get_field('user_image','user_' . $user_id);
$imagepath = $imagearray['url'];
update_field('image_url', $imagepath);
I don’t know if this code is even on the right track… How do I get this happen immediately when the user uploads the image? The image_url field should be saved along with the rest of their data.
Something like this will work for you. You will want to expand on this function to make sure the $imagearray and several other security checks.
function my_acf_save_post( $post_id ) {
$user_id = get_current_user_id();
$imagearray = get_field('user_image','user_' . $user_id);
$imagepath = $imagearray['url'];
update_field('image_url', $imagepath);
}
add_action('acf/save_post', 'my_acf_save_post', 20);