Non-empty events sorted by event date and other posts below in Bricks

Updated on 15 Jan 2024

Consider a scenario where you are showing posts from multiple post types namely post, event and game in a single query.

Also, events have an event_date custom field created using ACF.

By default, all the posts are ordered by date published in descending order.

Ex.:

Notice how there's no event date set for Event 6.

Requirement: Exclude the empty events and order the non-empty events by event date at the top, with the rest of the items of other post types below.

Like this:

This Pro tutorial shows how advanced meta queries using named clauses can be written and used in Bricks.

Here's how

Select the element on which query loop is enabled.

Select the post types in the query settings.

Turn on "Query editor (PHP)".

Paste:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to 390+ Bricks code tutorials with BricksLabs Pro