28th Jun '24
/
0 comments

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

Related Tutorials..

Pro
How to Modify Products Element Query in Bricks to Output Child Products

How to Modify Products Element Query in Bricks to Output Child Products

This Pro tutorial provides the steps to limit WooCommerce products output by Bricks' Products element on single product pages to only the children of the…
How to Add a Custom Control Field to an Element in Bricks

How to Add a Custom Control Field to an Element in Bricks

In this tutorial, we'll learn how to add a custom control field to an element and dynamically change a CSS property inside the builder. Introduction…
Categories:
Tags:
Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags:
Pro
Filtering Bricks Query Loop By Meta Box Relationship

Filtering Bricks Query Loop By Meta Box Relationship

In the Bricks Facebook group a user asks: Consider this setup: CPTs: Service Areas and City Pages Meta Box Relationship: City Pages to Service Areas…
Categories: