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

Related Tutorials..

Pro
City-based and Country-based Conditional Output in Bricks

City-based and Country-based Conditional Output in Bricks

This Pro tutorial provides the steps to render a Bricks element only if the visitor is from the specified country or city. Note: Caching may…
Categories:
Pro
Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Bricks lacks built-in dynamic tags for ACF field labels, prefixes, and suffixes. This tutorial shows how to add them using custom dynamic tags.
Categories:
How to List Your Posts Divided by Categories in Bricks

How to List Your Posts Divided by Categories in Bricks

In this tutorial, we'll learn how to display a list of posts divided by each category. The DOM tree Here is how I structured my…
Categories:
Pro
Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

This Pro tutorial provides the steps to modify a ACF Repeater query loop to only output the rows for which a True / False type…
Categories:
Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
Pro
User Role Conditional Output in Bricks

User Role Conditional Output in Bricks

This Pro tutorial provides the steps to output elements based on their CSS class to users of the specified role in WordPress when using Bricks…
Categories: