The code down below displays an array of flicker images from a plugin that works with Advanced Custom Fields. The problem I have is if I had previously selected a gallery to show but now deselect it I get an error 'Warning: Invalid argument supplied for foreach() in...'
How can I fix this? Obviously if nothing is selected or if something is deselected it shouldn't output anything.
Thanks and this is my first time using stackoverflow so I appreciated any help, please be gentle, I'm very much a novice at php. :)
<?php
$flickr_set = get_field(post_flickr_set);
echo '<div #id="flickr-set" class="flickr-gallery">';
if (isset($flickr_set['items'])) {
foreach ($flickr_set['items'] as $id => $photos) {
foreach ($photos as $photo) {
echo '<a href="' . $photo['large'] . '" title="' . $photo['title'] . '"><img src="' . $photo['thumb'] . '" /></a>';
}
}
echo '</div><!-- end flickr-set -->';
}
?>
You just have to check if the value is also an array like: