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 Builder query loop function? Case #1: the categories do not matter. Case #2: the categories matter.

This Pro tutorial provides the steps to tackle case #1 wherein we construct an array of IDs of latest posts assigned to 3 random categories in WordPress and use Bricks builder's bricks/posts/query_vars filter to pre-filter or limit the posts output by a Bricks query loop.

Step 1

Set up a query loop and set the query type to Posts.

Do not set any other settings.

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