Opens in a new tab
4th May '26
/
0 comments

Nested Query Loops with Dynamic Author Filtering in Bricks

This Pro tutorial provides the steps to set up nested query loops in Bricks for grouping posts by their authors.

For the posts under each author, we shall show one latest post with the rest appearing after an accordion's button is clicked.

Step 1

Install and activate BricksExtras.

Enable Pro Accordion element.

Step 2

Let's define three custom functions:

  • bl_get_loop_user(): returns the WP_User object from the specified loop (in this case, the outer user query loop)
  • bl_get_loop_user_prop(): returns the specified property (like ID) from the WP_User object currently being looped through in the outer user query loop
  • bl_get_loop_user_post_count(): returns the number of published posts authored by the user in a Bricks query loop minus 1

Add the following in child theme's functions.php (w/o the opening PHP tag) 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 634 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
How to Insert Element(s) Between Query Loop Posts in Bricks

How to Insert Element(s) Between Query Loop Posts in Bricks

Update on 16 Aug 2023: Follow this tutorial instead. This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth…
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
Masonry Accordion Query Loops in Bricks Builder

Masonry Accordion Query Loops in Bricks Builder

Learn how to enable masonry layout for nestable accordions in Bricks builder and use JavaScript to re-layout the masonry on accordions' open and close.
Categories:
Tags:
Pro
Search Results Grouped by Post Types in Bricks

Search Results Grouped by Post Types in Bricks

Updated on 08 Oct 2024 This Pro tutorial provides the steps to arrange the search results by specified post types in a Bricks site. We…
Displaying SureCart Featured Products & Products Collections with a Query Loop

Displaying SureCart Featured Products & Products Collections with a Query Loop

We walk through how to use a query loop to display SureCart products, featured products & collections.
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.