Check if ACF Array / Repeater field type is empty

Hi, Just wanted to share a nice feature. now that we have Twig. :slight_smile:

I’m not sure we could do this before via another method.

Used for conditions essentially to hide a section if the array was empty. or just fetch the length number.
{{ acf.post_field({“field”:“myRepeater”}) | length }}
If this can be done a better way it might be useful.

This is a nice to have essentially get the length of an array while filtering a key ‘type’ for a specific value
{{(acf.post_field({“field”:“myRepeater”}) |filter(item => item.type == 1)) | length}}

Maybe good for the docs.

1 Like

Hello Sam,

Thanks for sharing the information it will be helpful for other users to conditionally hide sections based on the length of an array, which is definitely a powerful feature using the Twig.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.