Support

Account

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

Solving

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:

    <?php 
    
    $images = get_field('gallery');
    
    if( $images ): ?>
        <ul>
            <?php foreach( $images as $image ): ?>
                <li>
                    <a href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                    </a>
                    <p><?php echo $image['caption']; ?></p>
                </li>
            <?php endforeach; ?>
        </ul>
    <?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.