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

Related Tutorials..

Pro
CMB2 Repeatable Group Bricks Query Loop

CMB2 Repeatable Group Bricks Query Loop

This Pro tutorial provides the steps to create a custom query loop type for outputting the subfield values of a Group field (repeatable) when using…
Pro
Posts Grouped by Post Dates in Bricks

Posts Grouped by Post Dates in Bricks

Setting up query loops for “Post Dates” with an the inner loop displaying all posts published on that day.
Categories:
Pro
Categories and SubCategories Query Loop Tabs in Bricks

Categories and SubCategories Query Loop Tabs in Bricks

Learn how to show top-level parent categories as tab titles and the corresponding subcategories as tab contents using Bricks nested queries.
Categories:
Pro
Posts from Random Categories in Bricks

Posts from Random Categories in Bricks

Updated on 31 Jul 2023 In BricksLabs Facebook group a user asked: How would you query 3 WordPress posts from 3 different categories with Brick…
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
Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Custom query loop for looping through SureCart product images.
Categories:
Tags: