@navzme
I managed to fix the images not showing up when editing the post, as well as the edit pencil icon not showing up issue (see the other thread I made earlier).
I had to make changes to your render_field.php, at the lines stated in the errors I posted earlier. I’ve mentioned what I have added, and where I have had to make changes to your code, I have just commented those lines out, and added my version below.
Basically, your $value isn’t a string… it is a nested array of all the images and their metadata (title, caption, url etc.) so the explode function was never going to work.
<?php
if( $value ):
// New Code
$attachment_ids = array();
foreach ($value as $attachments):
array_push($attachment_ids, $attachments['id']);
endforeach;
$acf_photo_gallery_editbox_caption_from_attachment = apply_filters( 'acf_photo_gallery_editbox_caption_from_attachment', $field);
//$acf_photo_gallery_attachments = $value;
//$acf_photo_gallery_attachments = explode(',', $acf_photo_gallery_attachments);
//$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $acf_photo_gallery_attachments );
$args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post__in' => $attachment_ids );
$acf_photo_gallery_attachments = get_posts( $args );
$nonce = wp_create_nonce('acf_photo_gallery_edit_save');
foreach($acf_photo_gallery_attachments as $attachment):
$id = $attachment->ID;
$url = get_post_meta($id, $field['_name'] . '_url', true);
$target = get_post_meta($id, $field['_name'] . '_target', true);
$title = $attachment->post_title;
if( $acf_photo_gallery_editbox_caption_from_attachment == 1 ){
$caption = wp_get_attachment_caption( $id );
} else {
$caption = $attachment->post_content;
}
acf_photo_gallery_edit($field['_name'], $nonce, $id, $url, $title, $caption, $target, $key, $replace_textarea_editor);
endforeach;
endif;
?>
</div>
<ul id="acf-photo-gallery-metabox-list" class="acf-photo-gallery-metabox-list">
<?php
if( $value ):
//$acf_photo_gallery_attachments = $value;
//$acf_photo_gallery_attachments = explode(',', $acf_photo_gallery_attachments);
//foreach($acf_photo_gallery_attachments as $image):
foreach($attachment_ids as $image):
?>
Unfortunately this now seems to have broken the Add Images button, which does nothing when clicked. Not quite sure why because what I changed doesn’t seem to be linked in any way.
Overall though, I am in a better position that I was previously, which is a good thing. I will investigate why the Add Images button no longer works and report back.
-
This reply was modified 4 years, 7 months ago by hshah.