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:

<?php 

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:

{echo:bl_get_acf_array_count(page_gallery)}

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.

Get access to all 524 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
Configuring Image Gallery dynamic source in Bricks

Configuring Image Gallery dynamic source in Bricks

Let's say you have a custom field created with ACF Pro of the type Gallery called "Property Gallery" for posts of "Property" CPT. In the…
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Pro
Month and Day Condition in Bricks

Month and Day Condition in Bricks

This Pro tutorial shows how we can define a custom function that takes in a month in the three-letter format (like Dec) and a day…
Categories:
Pro
How to Update Custom Fields with Default Values For Existing Posts when using ACF

How to Update Custom Fields with Default Values For Existing Posts when using ACF

Let's take a scenario where there are 10 Pages in a WordPress site. You proceed to create a Text-type of custom field called, say, "Custom…
Categories:
Tags:
Pro
ACF Taxonomy Field Value in Single Posts

ACF Taxonomy Field Value in Single Posts

Consider this scenario: CPT: Movie Movie CPT Taxonomy: Movie Genre Movie Genre Taxonomy's field: Genre Color Each movie will have only genre set. The requirement…
Categories:
Tags:
Pro
Sorting ACF Relationship Posts by Date Meta in Bricks

Sorting ACF Relationship Posts by Date Meta in Bricks

Consider the following setup: CPT: Events ACF Fields:Event Date Information (Group)|__Event Date (Date Picker)Pick Sub Events (Relationship) An Event can have 1 or more related…
Checking for Post Type in Bricks

Checking for Post Type in Bricks

A way to output elements conditionally based on the current post type in the loop in Bricks.
Categories:
Pro
ACF Repeater Row Count Condition in Bricks

ACF Repeater Row Count Condition in Bricks

This Pro tutorial provides the steps to output elements on single posts (of any post type) in Bricks only if a specific ACF Repeater-type of…
Categories: