2 add image id option
source | link

First in your first loop why do you break it? if there is no image in image_5 if someone just skip this and continue to image_6?

Second the ACF image field can return you an array with all the sizes. you need to set the field to return you Image Array

And then you can do something like this.

for($x = 1; $x <= 10; $x++) { 
    $img = get_field('image_' . $x);
    if($img) {
        ?>
            <a href="<?php echo $img['url']; ?>" class="open-viewer">
                <img src="<?php echo $img['sizes']['scaled']; ?>" alt="<?php echo $img['alt']; ?>">
            </a>
        <?php
    }
}

In case you can't return Image Array and you return the Image ID

for($x = 1; $x <= 10; $x++) { 
    $img_id = get_field('image_' . $x);
    if($img_id) {
        $fullsize_image = wp_get_attachment_image_src($img_id, 'full');
        ?>
            <a href="<?php echo $fullsize_image[0]; ?>" class="open-viewer">
                <?php echo wp_get_attachment_image($img_id, 'scaled'); ?>
            </a>
        <?php
    }
}

First in your first loop why do you break it? if there is no image in image_5 if someone just skip this and continue to image_6?

Second the ACF image field can return you an array with all the sizes. you need to set the field to return you Image Array

And then you can do something like this.

for($x = 1; $x <= 10; $x++) { 
    $img = get_field('image_' . $x);
    if($img) {
        ?>
            <a href="<?php echo $img['url']; ?>" class="open-viewer">
                <img src="<?php echo $img['sizes']['scaled']; ?>" alt="<?php echo $img['alt']; ?>">
            </a>
        <?php
    }
}

First in your first loop why do you break it? if there is no image in image_5 if someone just skip this and continue to image_6?

Second the ACF image field can return you an array with all the sizes. you need to set the field to return you Image Array

And then you can do something like this.

for($x = 1; $x <= 10; $x++) { 
    $img = get_field('image_' . $x);
    if($img) {
        ?>
            <a href="<?php echo $img['url']; ?>" class="open-viewer">
                <img src="<?php echo $img['sizes']['scaled']; ?>" alt="<?php echo $img['alt']; ?>">
            </a>
        <?php
    }
}

In case you can't return Image Array and you return the Image ID

for($x = 1; $x <= 10; $x++) { 
    $img_id = get_field('image_' . $x);
    if($img_id) {
        $fullsize_image = wp_get_attachment_image_src($img_id, 'full');
        ?>
            <a href="<?php echo $fullsize_image[0]; ?>" class="open-viewer">
                <?php echo wp_get_attachment_image($img_id, 'scaled'); ?>
            </a>
        <?php
    }
}
1
source | link

First in your first loop why do you break it? if there is no image in image_5 if someone just skip this and continue to image_6?

Second the ACF image field can return you an array with all the sizes. you need to set the field to return you Image Array

And then you can do something like this.

for($x = 1; $x <= 10; $x++) { 
    $img = get_field('image_' . $x);
    if($img) {
        ?>
            <a href="<?php echo $img['url']; ?>" class="open-viewer">
                <img src="<?php echo $img['sizes']['scaled']; ?>" alt="<?php echo $img['alt']; ?>">
            </a>
        <?php
    }
}