22nd Dec '23
/
0 comments

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 612 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

ACF Relationship: Count of Related Posts

ACF Relationship: Count of Related Posts

Looking to get the number of CPT B posts related to a CPT A post when using a Relationship field with ACF? Here's a custom…
Categories:
Tags:
Pro
“Pro” Category Ribbon for Posts in Bricks

“Pro” Category Ribbon for Posts in Bricks

This Pro tutorial provides the steps to show a "Pro" ribbon for posts that are categorized under the "Pro" category when using Bricks builder. Step…
Categories:
Pro
Querying Posts by ACF Date Sub Field in Bricks

Querying Posts by ACF Date Sub Field in Bricks

Updated on 17 Nov 2023. This Pro tutorial shows how we can set post__in query parameter of a query loop in Bricks to an array…
Categories:
Tags:
Pro
ACF Date Field Value Custom Format in Bricks

ACF Date Field Value Custom Format in Bricks

In the Bricks forum, a user asks: Hi there, I am setting up an events calendar using bricks. In some circumstances I would like to…
Categories:
Tags:
ACF Repeater Sub Field Values as Tabs in Bricks

ACF Repeater Sub Field Values as Tabs in Bricks

Bricks' query loop supports ACF Repeaters and Meta Box Groups out of the box besides posts, users and terms. This tutorial shows how we can…
Categories:
Tags:
Pro
Featured Image’s Meta in a Bricks Posts Query Loop

Featured Image’s Meta in a Bricks Posts Query Loop

How to output values of custom fields for the featured image of current post in a query loop
Categories:
Tags:
Pro
Conditional Output Based on ACF Date Field in Bricks

Conditional Output Based on ACF Date Field in Bricks

Updated on 1 Aug 2024 Looking to have a Section or other elements in Bricks rendered on the frontend only if today's date is before…
Categories:
Pro
Host Post’s Term in Bricks Query Loop

Host Post’s Term in Bricks Query Loop

Updated on 4 Mar 2025 In the BricksLabs Facebook group a user asked: Hi everyone, I’m facing a tricky situation that might have a simple…
Categories: