5th Nov '24
/
3 comments

Filtering Posts of a Bricks Query Loop by Meta Box Group’s Subfield Value

Updated on 8 Nov 2024

In the comments section of Sort Posts by Meta Box Group Sub Field in Bricks tutorial, a user asked:

That worked wonderfully! Is there also a tutorial how to show past events when the event year is in a group? Also how to show only future events in this scenario? : )

Consider this scenario:

CPT: event

Field group:Meta Box Group-type field: event_group|__ Number-type subfield: event_year

Test data:

When querying the event post type, all the event posts will be output by default:

The objective is to output only the events that are in the past.

i.e., as of 2024:

or only future/upcoming events:

This is not straightforward or doable via the built-in query editor controls due to the fact that the event year post meta is inside a Meta Box group.

This Pro tutorial shows how bricks/query/result Bricks filter can be used to limit the posts output by a Posts query loop based on the value of a Meta Box group's subfield value.

Update 1: Code for the case when the subfield type is Datepicker has been added near the end.

Step 1

Set up a query loop to output Events post type.

Add Heading/Basic Text etc. elements inside the query loop-enabled Block and map them to your post data like post title and the year subfield value.

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

Related Tutorials..

Pro
Recently Viewed Posts Bricks Query Loop

Recently Viewed Posts Bricks Query Loop

How to output the most recent X number of posts (any post type) viewed by the current visitor.
Categories:
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.
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:
Pro
x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

Showing how to display one random row of a Meta Box group for an hour and then output another random row.
Displaying SureCart Featured Products & Products Collections with a Query Loop

Displaying SureCart Featured Products & Products Collections with a Query Loop

We walk through how to use a query loop to display SureCart products, featured products & collections.
Categories:
Pro
Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Updated on 29 Feb 2024 In the Sibling Terms Bricks Query Loop tutorial, a member asked: How can I set the class "active" to the…
Categories:
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…
Pro
Post Views Counter Query Loop in Bricks

Post Views Counter Query Loop in Bricks

How we can output the most viewed posts in your Bricks site in a query loop.
Categories: