I am using ACF, NOT the pro version, and I also have a plugin called ACF Photo Gallery Field that I am using to make user albums. I used CPT UI to make the custom post type “Albums” and added the gallery field with ACF. I am also using Elementor Pro to make my custom post template and ACF Frontend Form plugin to put the edit album/create album forms on the templates so users can create their own albums and add more images to them from the frontend. I use the Code Snippets plugin to add codes to my functions.php. I have also used the gallery widget through Elementor Pro and used the dynamic content to add post attachments to the gallery so the images will show up on my albums. Also, I have a “Create New Album” page with a form for making a new album. Everything for that works except the upload images field when I try to add images to the newly created album as it is being created. It all works if i do it from the backend, but not from the frontend. The problem I am having is that the images I have uploaded using my edit album form and the images added during the create new album process are not attaching to the current album/new album being edited/created. I have been searching for a solution for several weeks and nothing I have tried is working. I am very new at PHP and website development, but I know the basics of how the codes work. I just don’t know how to go about making something work the way I want it to. Here’s some of the codes I have tried… See examples below: (BTW, the custom field is named “album_images”)
My website address is (https://headsandhair.com)(1) – it is still in development, so only coming soon page shows right now.
ATTEMPT 1: I added this to functions.php because this example was given by the ACF Gallery plugin. I’m not exactly sure WHAT it does or where it was supposed to go, so I just added it to the Code Snippets plugin.
<?php
//Get the images ids from the post_metadata
$images = acf_photo_gallery('album_images', $post->ID);
//Check if return array has anything in it
if( count($images) ):
//Cool, we got some data so now let's loop over it
foreach($images as $image):
$id = $image('id'); // The attachment id of the media
$title = $image('title'); //The title
$caption= $image('caption'); //The caption
$full_image_url= $image('full_image_url'); //Full size image url
$full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url
$thumbnail_image_url= $image('thumbnail_image_url'); //Get the thumbnail size image url 150px by 150px
$url= $image('url'); //Goto any link when clicked
$target= $image('target'); //Open normal or new tab
$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
$class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
?>
<div class="col-xs-6 col-md-3">
<div class="thumbnail">
<?php if( !empty($url) ){ ?><a href="https://wordpress.org/plugins/navz-photo-gallery/<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
<img src="https://wordpress.org/plugins/navz-photo-gallery/<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
<?php if( !empty($url) ){ ?></a><?php } ?>
</div>
</div>
<?php endforeach; endif; ?>
I also added this next snippet because it was also shown as an example on the gallery plugin…
acf_photo_gallery(album_images, POST_ID);
Then I tried this one because I saw it on this site somewhere…
function attachment_change_parent($aid,$pid) {
$update_attachment_post = array(
'ID' => $aid,
'post_parent' => $pid
);
wp_update_post($update_attachment_post);
}
And I have tried several more things, but to no avail. I am just not sure how to do it and the ACF website has no information for it either. If anyone can help steer me in the right direction, that would be great! All I want to do is have the images uploaded with my custom field attach to the post that they are being submitted from or attach to the album being created. It sounds like it should just be easy, but obviously it’s not…Thanks!!!