Posts Grouped by Categories in Bricks

This Pro tutorial provides the steps to set up nested query loops in Bricks with a Posts query inside a Terms query for showing posts grouped by their categories.

This method can be applied to show posts of any post type grouped by a corresponding taxonomy (built-in or custom), not just posts and categories.

In this example, we are showing post titles linking to their permalinks. Since we aren't using a Code element for outputting the loops we have full flexibility to visually develop the loop content by placing the various elements that Bricks builder provides.

Step 1

Copy and paste the Section from our test site using this JSON.

For the outer loop Block, the query type is set to Terms → Categories.

For the inner loop Block, the query type is set to Posts.

Step 2

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to all 250+ Bricks code tutorials with BricksLabs Pro