Oh, the number of times I’ve copied and pasted these code snippets …
The repeater field:
<?php if (have_rows('repeater_field')) { ?> <?php while (have_rows('repeater_field')) { the_row(); ?> <?php the_sub_field('sub_field'); ?> <!--Get repeater sub fields here...--> <?php } ?> <?php } ?> |
Image field
When the image field return type is array:
<?php $image = get_field('image'); if($image): $title = $image['title']; $alt = $image['alt']; $caption = $image['caption']; $size = 'thumbnail'; $thumb = $image['sizes'][ $size ]; $width = $image['sizes'][ $size . '-width' ]; $height = $image['sizes'][ $size . '-height' ]; ?> <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"> <?php endif; ?> |
When the image field return type is ID:
<?php $image = get_field('image'); if ($image) { echo wp_get_attachment_image($image, 'full'); } ?> |
Refer to https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ for documentation on using the “wp_get_attachment_image” function.