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

Related Tutorials..

Pro
Custom Nested Queries in Bricks

Custom Nested Queries in Bricks

In most of the previous tutorials covering nested query loops in Bricks on this site, we accessed the parent query's looping object in the inner…
Categories:
Pro
Query Loop Index in Bricks

Query Loop Index in Bricks

This Pro tutorial provides the code for getting the index of each post in Bricks' query loops. This can be used for either outputting the…
Categories:
Pro
6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

Displaying two set of random posts, inside one query loop.
Categories:
How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

This tutorial will explain how to enable the AJAX filter with an infinite scroll query loop container, how to add a sorting function, how to…
Categories:
Pro
Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Updated on 12 Dec 2023 Bricks Query Loop popup does not have a control for setting the number of posts to be output when the…
How to List Your Posts Divided by Categories in Bricks

How to List Your Posts Divided by Categories in Bricks

In this tutorial, we'll learn how to display a list of posts divided by each category. The DOM tree Here is how I structured my…
Categories:
Pro
Accordion Grid Query Loop in Bricks

Accordion Grid Query Loop in Bricks

How to set up a accordion in Bricks such that the "titles" are arranged in a grid with the full width content opening below.
Categories: