ACF Gallery Images Count Dynamic Condition in Bricks

Looking to output elements on single posts or in a query loop in Bricks based on how many images are present in the current post’s Gallery type custom field created using ACF Pro?

Add the following in child theme‘s functions.php (w/o the opening PHP tag) or a code snippets plugin:


function bl_get_acf_array_count( $field_name ): int {
    return count( get_field( $field_name ) );

Then use it with a Dynamic data condition like so:


where page_gallery is the name of your custom field.

This can be used with any ACF field that returns an array, not just Galleries.

Instant access to 390+ Bricks code tutorials with BricksLabs Pro

Leave the first comment