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

Related Tutorials..

Conditional Rendering for Logged in/out Users by CSS Classes in Bricks

Conditional Rendering for Logged in/out Users by CSS Classes in Bricks

This tutorial shows how Bricks builder's bricks/element/render filter can be used to conditionally output elements having a class of logged-in to logged-in users only and…
Categories:
Pro
ACF Relationship: Show all other events related to the artists of the current event

ACF Relationship: Show all other events related to the artists of the current event

How all other events related to the artists of the current event can be output in a Bricks query loop.
Categories:
Pro
Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

This Pro tutorial covers how posts of a Bricks query loop can be filtered to show only the ones whose true / false or checkbox…
Categories:
Tags:
Pro
Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

A couple of members asked: I have a cpt called "Markets" aand a cpt "tools". Tools have a taxonomy "tools group". How can i create…
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:
How to conditionally load your scripts based on an ACF field

How to conditionally load your scripts based on an ACF field

This tutorial provides the PHP codes that can be pasted in order to enqueue your scripts conditionally based on the value of an ACF field…
Categories: