WordPress Advanced Custom Field gallery doesn't return an array WordPress Advanced Custom Field gallery doesn't return an array wordpress wordpress

WordPress Advanced Custom Field gallery doesn't return an array


I think your problem comes from the fact that you are using get_field() instead get_fields(). That's way you don't get an array.

If it still doesn't work check the documentation for get_fields() here. Try to debug it like using only get_fields() and see what is the output. If it is an empty array then it means that you are calling the function out of the loop and it can't get the post id. So do a second test with manually setting the post id like get_fields(123); and check the results. If there are no results then there is something wrong with that post. And if there are results then you can do a final test with checking what will be the result of get_fields(123, 'gallery').

All the above debugging can be wrapped in something like:

echo '<pre>';    print_r( get_fields(123) );echo '</pre>';

Basically this will give you some idea of what is the structure of the data that you get from this function and how you can manipulate it so to get what you need.