Home › Forums › Back End › FOR loop with counter in variables › Re: FOR loop with counter in variables
Yea, noticed that, but that’s not the issue. I figured that it’s not the writing out of the string (that seems to work after all), it’s the part where I check if it exists. I did not included that in my original post cause I wanted to figure out the standard way of writing things first.
So in essence, this works:
for( $i=1; $i<4; $i++ ){
echo get_field( “product_image_$i” );
}
And this works too:
if (get_field(‘product_image_1’)) { echo get_field( “product_image_1” ); }
if (get_field(‘product_image_2’)) { echo get_field( “product_image_2” ); }
if (get_field(‘product_image_3’)) { echo get_field( “product_image_3” ); }
But this doesn’t:
for( $i=1; $i<4; $i++ ){
if (get_field(‘product_image_$i’)) { echo get_field( “product_image_$i” ); }
}
(FYI: get_field returns a simple value, in this case an image url)
Bah :(