Search code examples
phpwordpressrepeateradvanced-custom-fields

How to use Wordpress image sizes with Advanced Custom Fields


I have an acf repeater containing images. I am only grabbing the first row in the repeater as I only want to display that image. But I also want to set its size to the default large image size that WordPress automatically creates I have tried a couple solutions but I think I'm getting the syntax wrong. Can you show me?

Here's my code:

<?php 
    $floorplans = get_field('floorplans'); 
    $img = $floorplans[0]['floorplan'];
    ?>

<img src="<?php echo $img['url']; ?>" alt="">

Solution

  • Here's what I did to achieve this;

    <?php
        $floorplans = get_field('floorplans'); //gets the field
        $first_row = $floorplans[0]; //first row of field
        $img = $first_row['floorplan']; //gets the repeater field 
        $img_lrg = $img['sizes']['large']; //applies the size I want the image to be
    ?>