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

Related Tutorials..

Pro
Nested Queries in Bricks – Posts Grouped by Published Years and Categories

Nested Queries in Bricks – Posts Grouped by Published Years and Categories

In the past we showed how posts could be grouped by years in Bricks. This Pro tutorial takes it further by grouping posts by categories…
Categories:
Pro
CMB2 Repeatable Group Bricks Query Loop

CMB2 Repeatable Group Bricks Query Loop

This Pro tutorial provides the steps to create a custom query loop type for outputting the subfield values of a Group field (repeatable) when using…
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:
Auto Responsive Grids in Bricks

Auto Responsive Grids in Bricks

This tutorial provides the CSS that can be pasted for automatic responsive grids in Bricks Builder. Posts element Each post will get a right padding…
How to display a Query Loop in 3 columns in Bricks

How to display a Query Loop in 3 columns in Bricks

This tutorial provides the builder settings and CSS codes that can be pasted in order to create a 3-columns query loop container inside Bricks Builder.
Categories:
Pro
Related Services grouped by Service Categories on Single Branch Posts in Bricks

Related Services grouped by Service Categories on Single Branch Posts in Bricks

How to query ACF relationship fields on single CPT templates.
Categories: