29th Aug '24
/
1 comment

x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

A user asks:

Query a metabox group, but limit items?

...i cannot see how to pick a random text field in that group and change it every X minutes. is it doable?

i need to show only one item in the metabox group, at random, and randomly pick another after one hour.

btw, dunno why the groups have no options like posts or pages.

Non standard query types like ACF Repeaters, Meta Box Groups and Relationships do not have the same controls that the post query loops have.

This Pro tutorial shows how PHP transients and bricks/query/result filter can be used to specify how many random items should be output in the query loop's result set and for how long.

After implementing the tutorial, you could, for example, show one random row of a Meta Box group on page load, continue to show the same for an hour (the same for all visitors/users), and then output another random row (other than what was shown in the last hour) for the second hour and so on.

Before:

After:

After another hour:

Step 1

In a Bricks template or Page, set up your query loop.

In this example, we are querying a Meta Box group.

Step 2

Before we add the code snippet let's first understand what the original query result and the query object looks like.

Original query result:

This can be seen by adding this snippet in a code snippets plugin like WPCodeBox or in the child theme's functions.php at the end w/o the opening PHP tag:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 624 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
How to Add a Custom Control Field to an Element in Bricks

How to Add a Custom Control Field to an Element in Bricks

In this tutorial, we'll learn how to add a custom control field to an element and dynamically change a CSS property inside the builder. Introduction…
Categories:
Tags:
Term-specific single post template in Bricks

Term-specific single post template in Bricks

Updated on 25 Jun 2025 In Reddit a user asks: Template conditional logic to exclude pages with a particular taxonomy term? I can't figure out…
bricks/posts/merge_query Explained

bricks/posts/merge_query Explained

This short article provides details on Bricks' bricks/posts/merge_query filter. On pages rendered by an archive or search template, secondary queries like the ones used for…
Categories:
Tags:
Filtering out Media Items from “Select post/page” Bricks control

Filtering out Media Items from “Select post/page” Bricks control

The dropdown that appears after choosing "Internal post/page" when setting a link in Bricks shows media (attachment) items besides Pages, Posts and other CPTs. If…
Pro
Restrict Content Pro in Bricks

Restrict Content Pro in Bricks

This Pro tutorial provides the steps to restrict Pages and individual elements like Sections in Bricks depending on whether the current user has any active…