18th Jul '23
/
2 comments

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

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

In the past we showed how a Bricks posts query loop can be filtered by Meta Box group's subfield of types text/number and Datepicker here.…
Categories:
Pro
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Pro
Related Episodes Grouped by Episode Chapters on Single Podcasts in Bricks when using JetEngine

Related Episodes Grouped by Episode Chapters on Single Podcasts in Bricks when using JetEngine

A user asks: How to Display Related Episodes Grouped by Chapters on a Podcast Page in Bricks? Hi everyone, I have two post types created…
Bricks Templates Query Loop

Bricks Templates Query Loop

How display Bricks Templates with saved screenshots in a query loop.
Categories:
Bricks Query Loop – Posts Authored by Logged in User

Bricks Query Loop – Posts Authored by Logged in User

How to display only the posts authored by the currently logged-in user in a query loop.
Categories:
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: