Meta Box Group Bricks Query Loop Filtered by a True/False Subfield

In a project I am working on, the requirement is to show job positions but only those with a 'job opening status' set to Show.

Positions: A cloneable Group-type field
Job Opening Status: A Switch-type subfield

If there are no open jobs a separate text should appear.

When the Meta Box group is selected as the query type for the Bricks query loop, it outputs all the rows, including those for which the Job Opening Status subfield is false. This Pro tutorial shows how bricks/query/result filter can be used to limit the Meta Box group field's rows based on a boolean subfield value i.e., only show the open job positions.

Also, since the bricks_query_count dynamic data tag is not going to work for conditional checks due to use of the filter, we shall define a custom function to output either the jobs container or a fallback container conditionally.

Field group (for a specific Page in this example):

Page being edited:

Editor:

Front end:

When there's at least open job:

When there are no open jobs:

Step 1

In the Bricks editor set up a query loop and set the query type to your Meta Box group.

Add elements inside and map their text/URL values to subfield values using Bricks' dynamic data tags.

Step 2

Add the following in child theme's functions.php (w/o the opening PHP tag) 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 525 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Output HappyFiles Folders in Metabox Select-Field

Output HappyFiles Folders in Metabox Select-Field

This tutorial is part of a series where I'm gonna show you how to output custom HappyFiles Galleries and Sliders. Part one will cover a…
Categories:
Pro
Meta Box Date Field Value Custom Format in Bricks

Meta Box Date Field Value Custom Format in Bricks

Updated on 3 Apr 2024 Note: A custom function is no longer needed. Use the date format filter, as mentioned in the Bricks documentation. Ex.:…
Categories:
Tags:
Pro
Conditional Rendering Based on Current Date and Time in Bricks when Using Meta Box

Conditional Rendering Based on Current Date and Time in Bricks when Using Meta Box

A Pro member of our site asks: Using bricks + Meta, conditionally show a post listing under 3 different conditions, based on the Current Date…
Pro
Outputting Only the First ACF Repeater Row in Bricks

Outputting Only the First ACF Repeater Row in Bricks

Updated on 12 Dec 2023 In the Bricks Facebook group a user asks: How can I display only the first entry from an ACF repeater?…
Pro
How to programmatically add a class to an element in Bricks

How to programmatically add a class to an element in Bricks

This Pro tutorial shows how a dynamic class can be added to a query loop element in Bricks programmatically. Let's take an example where posts…
How to Exclude Elements from Bricks Editor

How to Exclude Elements from Bricks Editor

Bricks has a handy bricks/builder/elements filter using which the available elements that show up after clicking + (or ⌃/⌘ + ⇧ + E) in the…
Categories:
Tags: