Posts Grouped by Categories in Bricks

Update on 13 Nov 2023: There's a much simpler method here. But the following is still useful to get an understanding of how query loops in Bricks work.


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

Get access to all 526 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Loop Item ID and Loop Item Object in Bricks

Loop Item ID and Loop Item Object in Bricks

If you are working on a Bricks site with specific requirements, chances are you need to grab the ID and/or object of the current item…
Categories:
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Posts Related by Current Post’s Terms in Bricks

Posts Related by Current Post’s Terms in Bricks

Showing other posts assigned to the same categories/tags/custom taxonomy terms as the current post.
Categories:
Pro
Post-specific ACF Repeater Galleries as Sliders in Bricks

Post-specific ACF Repeater Galleries as Sliders in Bricks

How to output ACF Repeater field rows with the images of the Gallery-type sub field as a slider.
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
Posts Grouped by Authors in Bricks

Posts Grouped by Authors in Bricks

This Pro tutorial for Bricks users provides the steps to loop through users and inside that, through posts whilst setting the inner query's author parameter…
Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories: