Home › Forums › Front-end Issues › gallery Array › Reply To: gallery Array
A gallery field always returns an array of images/image data. An explanation of this is in the documentation https://www.advancedcustomfields.com/resources/gallery/.
A gallery field is one of the more advanced field types. The values of these fields cannot be simply echoed on the page, and they are not really appropriate for use with get_fields()
and looping over all the fields that are returned. In such a loop you would need to test for the different fields and do something different with these special fields.
<?php
$fields = get_fields($post->ID);
if ($fields) {
?>
<ul>
<?php
foreach ($fields as $name => $value) {
?>
<li>
<b><?php echo $name; ?></b>
<?php
if ($name == 'THE_NAME_OF_YOUR_GALLERY_FIELD') {
// do something special for gallery fields
} else {
// basic field
echo $value;
}
?>
</li>
<?php
} // end foreach fields
?>
</ul>
<?php
} // end if fields
?>
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.