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

Related Tutorials..

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:
Pro
How to Modify Products Element Query in Bricks to Output Child Products

How to Modify Products Element Query in Bricks to Output Child Products

This Pro tutorial provides the steps to limit WooCommerce products output by Bricks' Products element on single product pages to only the children of the…
Modifying ACF Field Value Before It Is Output

Modifying ACF Field Value Before It Is Output

Consider the scenario where a Page has a "Page Fields" field group created with ACF Pro like this: Field name: scientific_coordinators (type Repeater)|__ Sub field…
Categories:
Pro
Conditionally Hiding Bricks Filters based on Select Filter Value

Conditionally Hiding Bricks Filters based on Select Filter Value

How show or hide Bricks' filter based on the selection made by another filter.
Categories:
Tags:
Pro
Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

In the Bricks Facebook group a user asks: Consider this cloneable Meta Box field group for a Custom Post Type called Tour: with the Tour…
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: