Home Forums Add-ons Gallery Field get_field('galery') return false


get_field('galery') return false

  • Hi everyone I have a custom post type, inside I have a Gallery field, But in code when I try to get the images like $images = get_field(‘gallery’)inside the loop of WordPress I obtain a false value;

    Any idea?

  • what code do you use to display the gallery? and what is your gallery-fieldname?
    gallery is an array, that means you need a foreach loop like this to show the images inside that array:

    $images = get_field('gallery');
    if( $images ): ?>
            <?php foreach( $images as $image ): ?>
                    <a href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                    <p><?php echo $image['caption']; ?></p>
            <?php endforeach; ?>
    <?php endif; ?>
  • Hi @maitep

    It is also possible that you have not correctly set the location rule or the post id.

    The function will return false if no value is found.

    I hope this helps.

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

The topic ‘get_field('galery') return false’ is closed to new replies.