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

Related Tutorials..

How to show data of a post whose ID is the value of a URL parameter in Bricks

How to show data of a post whose ID is the value of a URL parameter in Bricks

In the Bricks Facebook group, a user asks: Hey Everyone,I am trying to create the following:1- I have a Custom Post Type2- I have a…
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:
Pro
Bricks Query Loop for Top-level Parent Pages with Children

Bricks Query Loop for Top-level Parent Pages with Children

In the Bricks Facebook group, a user asked: Looking for a custom query to output a list of posts in the same hierarchy that the…
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
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Querying Posts by Date Field to Exclude Past Events with ACPT Plugin

Querying Posts by Date Field to Exclude Past Events with ACPT Plugin

In the Bricks' Facebook group, a user asked: Meta query? What am I missing?Hi all, really need a little guidance on this one. I have…
Categories: