I purchased two ACF add-ons (gallery & options panel). I installed ACF and both plugins but cannot seem to get the gallery to run. I created the appropriate custom field (‘gallery’) and added four images from the media gallery to it.
To test it I then called
var_dump( get_field('gallery') ); but unfortunately it doesn’t return an array but
Because you are saving / loading data from the options page add-on, you must also remember to specify the $post_id parameter as shown in this doc:
Basically, the get_field should look like:
Im still having this exact problem even with this “solution”
<?php $gallery = get_sub_field('gallery', 'option'); foreach($gallery as $photo):?> <a href="<?php echo $photo['url']; ?>" class="cbox item"> <img src="<?php echo $photo['sizes']['thumbnail']; ?>"/> </a> <?php endforeach;?>
The name of the field is gallery.
additionally I tried to pass in the post id into the second param :
<?php $postid = get_the_ID(); $gallery = get_sub_field('gallery', $postid); foreach($gallery as $photos): ?> <a href="<?php echo $photos['url']; ?>" class="cbox item"> <img src="<?php echo $photos['sizes']['thumbnail']; ?>"/> </a> <?php endforeach;?>
Any thoughts sir ?
when I var dump the $gallery obj it returns bool
php errors are the same “Invalid value in foreach”
I just reverted our ACF plugins back to 4.2.2 and it works now.
The topic ‘Gallery plugin does not return array’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.— Advanced Custom Fields (@wp_acf) January 6, 2023
© 2023 Advanced Custom Fields.