Support

Account

Home Forums General Issues ACF Gallery displaying attachment fields

Unread

ACF Gallery displaying attachment fields

  • I have a Gallery field inside flexible content.

    I also have a Select field on media attachments called ‘data_category’. This field allows multiple selections.

    I am trying to display the values from the ‘data_category’ attachment field along with each image in the gallery.

    <?php 
    $images = get_sub_field('gallery');
    if( $images ): ?>
        <div class="grid">
            <?php foreach( $images as $image ): ?>
    			<?php $data_category = get_field('data_category', $image['ID']);?>
                <a href="<?php echo $image['url']; ?>" class="element-item category_name" data-category="category_name">
    				<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" title="<?php echo $image['title']; ?>" />
    				<?php echo $data_category;?>
                </a>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>

    When the code is rendered, instead of the data_category being displayed, it just says ‘Array’. This happens when the return format is set to Label or Value. When I set the return format to Both, nothing shows.

    Does anyone know what I need to change to get it working?

    Many thanks.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.