15th Mar '26
/
0 comments

Per-Category Load More with Post Count in Bricks Builder Nested Query Loops

In the BricksLabs group, a user asks:

Hi everyone!

I'm working on a website where I need to list a large number of products on the product archive page, which would slow down the website.

Currently, the page structure works as follows: there is a query that lists the product categories ("Telefonok", "Tabletek", etc.), and within that there is another query that lists the products of the given category.

My idea was to display 4-5 products per category, and when the user clicks the "Load More" button, additional products would appear (it would also be fine if, when the user clicks "Load More" within a given category, it triggers infinite scroll so that products load automatically on scroll — but only within that specific category).

My main problem is that since the product categories are also dynamic (they come from a query), I can't choose a unique CSS selector for the AJAX-based loading, so the infinite loader doesn't work either.

Please advise on how this problem can be overcome. Thank you!

This Pro tutorial provides the steps to make Load more buttons below posts under categories work in Bricks when using nested query loops.

Bricks Builder's native Load more interaction breaks down in nested query loops. For example, when posts are grouped inside a taxonomy loop, every category shares the same query instance key, so clicking any Load more button loads posts for the wrong category or affects all groups at once.

This tutorial walks through a complete solution using a Bricks Component to encapsulate the per-group markup, a custom JavaScript file that reads Bricks' internal query trail elements before they are removed from the DOM, and a custom PHP dynamic data tag {bl_remaining_posts} that reports how many posts remain per group on initial page load.

Our solution also covers keeping the remaining count in sync after each AJAX load, wiring up Bricks' built-in AJAX loader animations so the correct spinner appears inside the active group only, and hiding buttons once all posts for a given term are loaded.

Step 1

Edit your Page/Template with Bricks, copy the fully-built Section's JSON from our site and paste.

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 633 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
Parent Query Loop Object – Traversing Nested Query Loops Up in Bricks

Parent Query Loop Object – Traversing Nested Query Loops Up in Bricks

Bricks enables us to build nested query levels of unlimited levels. Here are a couple of examples: Sometimes, you might want to obtain the parent…
Categories:
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:
Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements: