I am using the ACF Plugin. I want to have a field where I can upload an image, and the result will display the full image in the Lightbox and then then full image will be resized into a thumbnail from that field (like a normal Lightbox).

So far I have the script here, and this is where I am at:

<div class="single last">
<a href="<?php echo the_field('image_gallery'); ?>" rel="lightbox" title="<?php the_title(); ?>">

$main_car_pic = addslashes(the_repeater_field('image_gallery'));
$reg_ext = "#.jpg#i";
$thumb_ext = "-150x150.jpg";
$car_thumb = preg_replace($reg_ext, $thumb_ext, $main_car_pic);

echo $car_thumb

The ACF Repeater field isn't working properly and I cannot work why, does anybody have any experience with ACF and resizing images for thumbnails.. Hope what code I have done helps and I'll be really appreciate it, if nto comment and I can supply anything that might help.

  • I don't think this Question may help future visitors. Seems like a programming issue more fit in the support forum. Flagging as too localized. . . . . Owen, there's an error in the code: either use echo get_the_field() or simply the_field(). Also, check the plugin documentation and do some echo's and var_dump's to track your output.
    – brasofilo
    Jul 13, 2012 at 0:42
  • @brasofilo didn't mean it to be a problem really, as seen, this is quite new to me, getting my head round wordpress and php. All I want to do is to be able to load the same image twice in two different locations from a repeating field. I'll have to have better look in the morning as I have spent hours looking at the screen. Jul 13, 2012 at 0:56
  • good reminder on the echo's and var_dump, forgot, appreciate it and thank you for your help. Jul 13, 2012 at 0:56

1 Answer 1


There's a lot going on here. First off, you should store the repeater field image as an ID (that probably requires changing how the subfield's setting and possibly re-uploading some of your images) and then use all the WordPress Core API functions to handle it. (You'll probably cross paths with wp_get_attachment_image_src.) That gets rid of your regex-ing, makes your image sizing take advantage of add_image_size, etc.

Second, you need to follow the repeater field's code example on the page you linked to. get_repeater_field() returns an object you can iterate through with a loop-like while statement and get_sub_field(). (As an aside: get_field( 'a_repeater_field' ) returns an array you can iterate through with a foreach statement.)

Your final code will look something like this:

<?php if( get_field('image_gallery') ) {
    while( the_repeater_field('image_gallery') ) {
        $large_img_src = wp_get_attachment_image_src( get_subfield('an_image_subfield'), 'large' );
        echo '<a href="' . $large_img_src[0] . '">' . wp_get_attachment_image( get_sub_field('an_image_subfield'), 'thumbnail' ) . '</a>';
} ?>

You can replace 'thumbnail' and 'large' with an array or a custom image size.

  • Uou. I was flagging as too localized and writing a comment while you were doing such nice answer/solution/interpretation-of-the-question, kudos!
    – brasofilo
    Jul 13, 2012 at 0:45
  • @mrwweb - bare with me as I am trying to get my head around this.. I tried your code and change the value's from url to ID's. This would make sense as I need them sa ID's to set different sizes and run them through loops. Jul 13, 2012 at 0:49
  • Thus being able to have the same image, as a thumbnail and as a large image, just calling it in twice and changing sizes, right? - also when the_repeater_field is set to 'image-gallery' it actually conflicts with the page and it doesn't load, so based on what else I've got I would assume that they are conflicting somehow. But you have definitely set me on the right track! Jul 13, 2012 at 0:52
  • Thanks for your help! I'll have a sit down and try get to the bottom of this.. Jul 13, 2012 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.