15th Dec '25
/
0 comments

Hierarchical Posts with Nested Query Loops in Bricks

A user asked:

Hi there, I'm looking for a couple of tutorials...I have a CPT and inside there are a bunch of posts, and some of those posts have children.

I need to adapt the query on the archive page to ONLY show the parents.

I also need another query that I can put inside the above query to show links to the CHILDREN (if there are any).  I think I can use this tutorial to do that:

Thank you!

This Pro tutorial provides the steps to output child posts grouped under their parent post of a CPT in Bricks using nested query loops.

Posts list:

After implementing the tutorial:

We shall order the

  • parent posts in the outer query loop in ascending order of post titles
  • child posts in the inner query loop in descending order of post publish dates (the default)

It is possible to change the order for both query loops depending on the requirements.

Copy the JSON below the screenshot and paste in your Bricks Page/template.

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 611 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Current Single Post Reference From Inside a Bricks Query Loop

Current Single Post Reference From Inside a Bricks Query Loop

Use case: Get the single post’s custom field (like ACF Repeater or Meta Box Group) array row corresponding to the loop’s counter/index
Categories:
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
Upcoming Events Grouped by ‘Month Year’ in Bricks

Upcoming Events Grouped by ‘Month Year’ in Bricks

A custom query loop type for showing future events based on a date custom field using three nested query loops.
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
Custom SQL Ordering for Sorting Events in Bricks

Custom SQL Ordering for Sorting Events in Bricks

Showing events ordered by the event date with upcoming events in ascending order and past events in descending order.
Categories:
Load more for Query loops in Bricks

Load more for Query loops in Bricks

Did you know that Bricks has AJAX loading for query loop posts on-click out of the box?
Categories:
Pro
Upcoming Events with ACF Date Sub field Repeaters grouped by Month Years in Bricks

Upcoming Events with ACF Date Sub field Repeaters grouped by Month Years in Bricks

In the comments section of Upcoming Events Accordion in Bricks Grouped by 'Month Year' a member asked: CPT: eventACF Field: event_dates (Repeater) with event_date sub…
Categories: