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

Related Tutorials..

Pro
ACF Relationship Select Filter in Bricks

ACF Relationship Select Filter in Bricks

In the BricksLabs Facebook group, a user asks: I'm learning about ACF relationships and attempting to output a list of posts on any given page,…
Categories:
Pro
Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Updated on 12 Dec 2023 Bricks Query Loop popup does not have a control for setting the number of posts to be output when the…
Pro
Random Row from ACF Repeater in Bricks

Random Row from ACF Repeater in Bricks

In the past, we shared how the first row of a ACF Repeater can be output in a Bricks query loop here. This Pro tutorial…
Pro
Sort Posts by Meta Box Group Sub Field in Bricks

Sort Posts by Meta Box Group Sub Field in Bricks

This Pro tutorial provides the steps to order posts in Bricks by the value of a Number-type of sub field that is inside a Meta…
Pro
Ordering Meta Box group rows by a sub field in Bricks

Ordering Meta Box group rows by a sub field in Bricks

In the BricksLabs Facebook group a user asks: Any idea how to set the sort order of a cloneable group in the query? In this…
How to Remove Name and Website Fields in Bricks Comment Forms

How to Remove Name and Website Fields in Bricks Comment Forms

Updated on 14 Mar 2024 In the BricksLabs Facebook group a user asked: What is the best method to remove fields from the Bricks "Comments"…
Pro
Making a Nav Menu Item Active for Custom Post Type Single Views in WordPress

Making a Nav Menu Item Active for Custom Post Type Single Views in WordPress

Consider this scenario: CPT: project Page titled "Project" is being used to show a list/grid of all the projects rather than the CPT archive. When…
Categories: