Home Forums Add-ons Repeater Field Repeater field images to Gallery Image


Repeater field images to Gallery Image

  • I have a submission form on my website, I try to get images from the repeater field to gallery images and it’s work. I have just followed John Huebner answer here:

    But, the problem is, when I tried to edit the gallery image, I added a new image, but the new image wasn’t updated. Only the image of the form submission is there.

    Any idea how to get this done?

    // Set Repeater Image as Gallery Images
    function my_acf_save_post($post_id) {
        $repeater = 'preview_images_row';
        $subfield = 'preview_images_file';
        // using get_post_meta because that way we're sure to get the image ID
        $count = intval(get_post_meta($post_id, $repeater, true));
        $images = array();
        for ($i=0; $i<$count; $i++) {
            $field = $repeater.'_'.$i.'_'.$subfield;
            $images[] = intval(get_post_meta($post_id, $field, true));
        update_post_meta($post_id, 'preview_images', $images);
    add_action('acf/save_post', 'my_acf_save_post', 20); // priority of 20 so it runs after ACF

    See the video here:

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.