Opens in a new tab
18th Nov '24
/
0 comments

Ordering Posts by Terms in Bricks

In the Bricks Facebook group a user asks:

Hello everyone. I have a CPT 'events' and a taxonomy 'event-did-it-happen' in which there are two items 'past' and 'upcoming'.

I need to list all the 'events' posts sorted by 'event-did-it-happen' in a loop so that they are 'upcomming' first and then 'past'.

I have created a query that works for me, but as soon as I use it in Bricks as a custom query, the posts are sorted randomly.

How to go about it? Thank you

This Pro tutorial shows how to output upcoming events at the top and past events below in a single query loop in Bricks.

Consider this scenario:

CPT: EventTaxonomy: Event StatusTerms: Upcoming, Past

Default output:

After implementing the tutorial:

Note: There is no 'Event Date' custom field in this example. Within each taxonomy group (Upcoming and Past), posts will be set to be shown in descending order of published date.

If you want to instead order events based on the Event Date field automatically without manually assigning them 'Upcoming' or 'Past' Event Status taxonomy terms, follow the Custom SQL Ordering for Sorting Events in Bricks tutorial instead.

Step 1

Enable query loop on a Block.

Click the query icon and select your Event post type.

Enable PHP query editor and paste:

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
Querying Posts by ACF Date Sub Field in Bricks

Querying Posts by ACF Date Sub Field in Bricks

Updated on 17 Nov 2023. This Pro tutorial shows how we can set post__in query parameter of a query loop in Bricks to an array…
Categories:
Tags:
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Pro
Child Posts Section in Bricks

Child Posts Section in Bricks

This Pro tutorial provides the steps to limit the posts (can be of any post type) output by Bricks' query loop to children of the…
Categories:
Pro
Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Custom query loop for looping through SureCart product images.
Categories:
Tags:
Pro
Posts older than today in Bricks

Posts older than today in Bricks

How to display only posts that were published before today in a query loop.
Categories:
Pro
CPT Posts Grouped by Custom Taxonomy Terms in Bricks

CPT Posts Grouped by Custom Taxonomy Terms in Bricks

The steps to set up a Service Category terms loop with an inner Service posts loop in Bricks without writing code.
Categories:
Pro
How to Query WordPress Taxonomy Terms by Hierarchy Level in Bricks

How to Query WordPress Taxonomy Terms by Hierarchy Level in Bricks

How to limit the terms of a Bricks Terms query to only those at a specific level within the taxonomy hierarchy.
Categories:
Loop Item ID and Loop Item Object in Bricks

Loop Item ID and Loop Item Object in Bricks

If you are working on a Bricks site with specific requirements, chances are you need to grab the ID and/or object of the current item…
Categories: