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

Related Tutorials..

Pro
Querying Posts by Date/Datetime Custom Fields in Bricks

Querying Posts by Date/Datetime Custom Fields in Bricks

This Pro tutorial shows how to configure ACF and Meta Box to query posts in Bricks by custom field(s) of the type Date/Date Time Picker…
Categories:
Tags:
Pro
Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

On product pages, we show all the FAQs associated with the current WooCommerce product's product categories.
Categories:
Conditions in Bricks Builder

Conditions in Bricks Builder

The current version of Bricks does not have a built-in Conditions feature but that does not mean we can't set them up manually with custom…
Categories:
ACF Checkbox Items with Custom SVG Bullets in Bricks

ACF Checkbox Items with Custom SVG Bullets in Bricks

We walk through outputting list items with SVG icons based on the choice of a ACF Checkbox field.
Categories:
Tags:
Pro
Filtering ACF Relationship Query by Post Meta in Bricks

Filtering ACF Relationship Query by Post Meta in Bricks

How to filter the posts of a post type related to another post type based on the value of a True / False type ACF…
Pro
ACF Relationship Select Filter in Bricks

ACF Relationship Select Filter in Bricks

In the BricksLabs Facebook group, a user asks: I'm learning about ACF relationships and attempting to output a list of posts on any given page,…
Categories:
Pro
Check If The Latest Post Was Published in The Last X Minutes

Check If The Latest Post Was Published in The Last X Minutes

In this Pro tutorial we shall define a custom function that takes in the number of minutes as an argument and returns true if there…
Categories: