Hi there,
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 bool(false)
instead.
Any idea?
Hi @dom
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:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-an-options-page/
Basically, the get_field should look like:
get_field('gallery', 'option')
Thanks
E
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”
UPDATE:
I just reverted our ACF plugins back to 4.2.2 and it works now.
Hi @monostereo
The code you posted, shows you are using the get_sub_field function This is very different from get_field.
Is the gallery field a sub field?
Thanks
E
In my case, I am using the gallery as a sub field. It works fine on my localhost but not on my test server. What could be going on?