Title: Editing Post &#8211; Loading Field
Last modified: April 25, 2020

---

# Editing Post – Loading Field

 *  [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/editing-post-loading-field/)
 * After selecting images using this Photo Gallery field, I am using the ‘acf/save_post’
   action to set each image as an attachment by setting their post_parent field 
   with the post_id.
 * When I go to edit the post again from the frontend, the Photo Gallery field shows
   no images. If I do the same from the backend, the images I added before are present.
 * The other ACF fields are populated when I try and edit the post from the frontend,
   so I don’t understand why the Photo Gallery field isn’t populated as well, especially
   since it is when editing the post from the backend.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/editing-post-loading-field/#post-12731248)
 * I am seeing errors like this when the post is loaded in the frontend, so not 
   sure if that is related:
 *     ```
       [25-Apr-2020 19:31:03 UTC] PHP Warning:  explode() expects parameter 2 to be string, array given in /wp-content/plugins/navz-photo-gallery/includes/render_field.php on line 34
       [25-Apr-2020 19:31:04 UTC] PHP Warning:  explode() expects parameter 2 to be string, array given in /wp-content/plugins/navz-photo-gallery/includes/render_field.php on line 57
       [25-Apr-2020 19:31:04 UTC] PHP Warning:  Invalid argument supplied for foreach() in /wp-content/plugins/navz-photo-gallery/includes/render_field.php on line 58
       ```
   
 *  Thread Starter [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/editing-post-loading-field/#post-12731282)
 * [@navzme](https://wordpress.org/support/users/navzme/)
 * My issue seems to be the same as this one from over a year ago:
    [https://wordpress.org/support/topic/gallery-in-group-field/](https://wordpress.org/support/topic/gallery-in-group-field/)
 * And the errors I mentioned are just like this one (yes, I have set the label 
   etc):
    [https://wordpress.org/support/topic/php-warnings-57/](https://wordpress.org/support/topic/php-warnings-57/)
 * /Edit:
    I logged the entire $_POST when saving. My Photo Gallery field is called
   _gallery_ and its key is _field\_5ea463d262a41_. You can see the 3 test images
   I added, but I don’t see them when editing the post from the frontend. I also
   find it odd that the key name isn’t mentioned anywhere.
 *     ```
          [_acf_screen] => acf_form
           [_acf_post_id] => 12299
           [_acf_validation] => 1
           [_acf_nonce] => 
           [_acf_changed] => 0
           [acf] => Array
               (
                   [field_5e9466f65b151] => blah
                   [field_5e938ffe6a7f7] => sdfsdfsdf
                   [field_5e9f9f307fafe] => no
               )
   
           [custom_title] => field_5e9466f65b151
           [custom_content] => field_5e938ffe6a7f7
           [custom_excerpt] => field_5e938ffe6a7f7
           [acf-photo-gallery-edit-modal] => Default
           [acf-photo-gallery-groups] => Array
               (
                   [0] => gallery
               )
   
           [acf-photo-gallery-images_limit] => 
           [gallery] => Array
               (
                   [0] => 12295
                   [1] => 12316
                   [2] => 12413
               )
   
           [acfef_widget_id] => 666d69e
           [acfef_post_id] => 11475
           [acfef_success] => Album Updated
           [acfef_main_action] => edit_post
       ```
   
    -  This reply was modified 6 years, 1 month ago by [hshah](https://wordpress.org/support/users/hshah/).
    -  This reply was modified 6 years, 1 month ago by [hshah](https://wordpress.org/support/users/hshah/).
 *  Thread Starter [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/editing-post-loading-field/#post-12731540)
 * [@navzme](https://wordpress.org/support/users/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 6 years, 1 month ago by [hshah](https://wordpress.org/support/users/hshah/).
 *  Thread Starter [hshah](https://wordpress.org/support/users/hshah/)
 * (@hshah)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/editing-post-loading-field/#post-12731592)
 * **Update:**
 * The Add Images button works fine lol. I forgot that I had commented out my own
   function which enqueued `wp_enqueue_media()` and other related scripts/styles.
 * 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Editing Post – Loading Field’ is closed to new replies.

 * ![](https://ps.w.org/navz-photo-gallery/assets/icon-128x128.png?rev=2607741)
 * [ACF Photo Gallery Field](https://wordpress.org/plugins/navz-photo-gallery/)
 * [Support Threads](https://wordpress.org/support/plugin/navz-photo-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/navz-photo-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/navz-photo-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/navz-photo-gallery/reviews/)

 * 4 replies
 * 1 participant
 * Last reply from: [hshah](https://wordpress.org/support/users/hshah/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/editing-post-loading-field/#post-12731592)
 * Status: not resolved