11th Jan '24
/
0 comments

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro) Repeater field has a specified sub field whose value matches the specified string.

We shall define a custom function that takes these 3 arguments so it can be used with Bricks' Dynamic data condition:

  • repeater name
  • sub field name
  • a string to check

This can also be applied to posts in a query loop.

Consider this scenario:

Game CPT having a Quote ACF Repeater type of field having these sub fields: Quote Amount (Number) and Quote Item (Select).

JSON export (you need to add a game CPT first)

"Game 1" entry when edited:

Requirement: When this "Game 1" post is being viewed on the front end, we want a Section that shows the Repeater data to be output only if, say, the Quote Item of "Bats" is present in at least 1 of the Repeater rows.

After implementing this tutorial:

When "Game 2" for which either the Quote Repeater field is empty or no row's Quote Item has "Bats", the Section won't be output:

Step 1

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 626 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Bricks Dynamic Condition – Check if today falls within 5 days before any holiday date

Bricks Dynamic Condition – Check if today falls within 5 days before any holiday date

Creating a custom condition that returns true or false depending on whether today falls within 5 days before any holiday dates selected on a Meta…
Categories:
Tags:
Custom Function for ACF Link Field

Custom Function for ACF Link Field

How to output the label of an ACF link field through Dynamic Data.
Categories:
Tags:
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…
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Pro
User Role Condition in Bricks

User Role Condition in Bricks

This Pro tutorial provides the steps to conditionally output elements depending on the currently logged-in user's role. Step 1 Create a section Template having the…
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:
Conditional Output based on Manual Excerpt in Bricks

Conditional Output based on Manual Excerpt in Bricks

How to display a post’s excerpt only if it has been manually set.
Categories:
Pro
Related Services grouped by Service Categories on Single Branch Posts in Bricks

Related Services grouped by Service Categories on Single Branch Posts in Bricks

How to query ACF relationship fields on single CPT templates.
Categories: