Support

Account

Home Forums ACF PRO Select field as list item category for a gallery always gives first saved option

Solved

Select field as list item category for a gallery always gives first saved option

  • Hey all,

    I just got me the pro plugin (which is great!)
    But i have a small problem with displaying a select field inside a foreach loop.
    I tried a whole lot of things but i always ended up only getting the field option i saved last.

    This is my loop:

    <?php 
    				$images = get_field('gallerij');
    				if( $images ): ?>
    					<ul>
    						<?php foreach( $images as $image ): ?>
    							<li class="<?php echo the_field('orientation'); ?>">
    								<a href="<?php echo $image['url']; ?>">
    									 <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
    								</a>
    							</li>
    						<?php endforeach; ?>
    					</ul>
    				<?php endif; ?>

    So i get an output from the field “orientation”(this is a field attached to the attachments) but it always repeats the same value although i changed all of them.

    Could anyone point me in the right direction since i have been reworking this “probably” simple loop for a bout 5 hours. The above example is the one i started with.

    Quite desperate over here :). Hope someone can help.

    Thanks in advance

    Jannik

  • You need to specify the image id when getting a field from an attachment

    <?php echo the_field('orientation', $image['ID']); ?>

  • Omg so stupid. Could run face first into the wall right now…

    Thank you John!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Select field as list item category for a gallery always gives first saved option’ is closed to new replies.