14th Jan '24
/
0 comments

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

Get access to all 626 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Excluding Duplicate Posts from Query Loops in Bricks

Excluding Duplicate Posts from Query Loops in Bricks

How to ensure that posts are not duplicated when two query loops are used on the same page.
Categories:
Pro
Post ID Query Variable-based Post Output in Bricks

Post ID Query Variable-based Post Output in Bricks

How to query a single post of a custom post type using the post ID passed to a page via a URL parameter.
Pro
Single Event Template for The Events Calendar in Bricks

Single Event Template for The Events Calendar in Bricks

Updated on 19 Sep 2024 The Events Calendar is one of the most popular event plugins for WordPress. With The Events Calendar active, single event…
Pro
Hierarchical Posts with Nested Query Loops in Bricks

Hierarchical Posts with Nested Query Loops in Bricks

Learn how to set up nested query loops in Bricks to show hierarchical posts with child posts grouped under their corresponding parent posts
Categories:
Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories: