Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End FOR loop with counter in variables Re: FOR loop with counter in variables

#135747
__
Participant

> `the_field( ‘”product_image_’.$i.'”‘ );`

too many quotes.

If `get_field()` **returns** a value, or false if there is no value, then you can do like so:

for( $i=1; $i<4; $i++ ){

# note: double-quotes around whole string
$var = get_field( “product_image_$i” );

# assuming you want to output *now*
if( $var ){ echo $var; }
}