For example, if you have a repeater field name ‘list’.
$list = get_field('list');
should return an array of sub fields. but if a post hasn’t been saved since that custom field has been added (or it has been saved but doesn’t have any rows in the repeater), it will not have any database field for that ‘list’ value, and ACF thus returns a null or 0 value. But it should return an empty array, as that is what you would get if the post had been saved with rows of values.
You should be able to foreach (get_field('list') as $item), but right now that can result in PHP warnings because get_field('list') isn’t always an array.
get_field() is a diverse function. For instance, you may want to hide empty fields in your template using conditionals and this could be why get_field() returns null or false if a field does not contain any values.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp