Bricks Query Loop: Outputting a Fixed Number of Items

Bricks Query Loop: Outputting a Fixed Number of Items

In the BricksLabs Facebook group a user asks:

How might I repeat query loop items until it reaches a specific number?

One service might have 7 images, another might have 10, but there needs to be exactly 13, so they need to loop again until 13 is reached.

This Pro tutorial shows how bricks/query/result filter can be used to intercept the query result and modify it to output a fixed number of items by re-using the items.

We shall cover two types of queries - Meta Box cloneable group and Posts.

Meta Box Cloneable Group

Consider a "Features" group-type field having "Feature Name" and "Feature Details" subfields.

Field populated for a specific Page:

In the Bricks editor setting up a query loop for this Meta Box group shows the three items like this:

The requirement is to show exactly 13 items by filling the remaining 10 slots with the existing ones, like this (screenshot after implementing the tutorial):

Here's how.

Add the following in child theme's functions.php (w/o the opening PHP tag) 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 558 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Limiting the Query Loop Posts Output to Post IDs From a Custom Field in Bricks

Limiting the Query Loop Posts Output to Post IDs From a Custom Field in Bricks

A user asks: Recently Bricks introduced the PHP query editor that lets us modify the query parameters right within the query dialog of the builder…
Categories:
Tags:
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
Bricks Dynamic Condition – Check if today falls within 5 days before any holiday date

Bricks Dynamic Condition – Check if today falls within 5 days before any holiday date

In the members-only Tutorial Requests section, a user asks Conditionally show a banner if date exists and is equal to today + 5 days before…
Categories:
Tags:
Meta Box Category Colors in Single Posts

Meta Box Category Colors in Single Posts

Looking to use Meta Box Color Picker fields' values in a single post Bricks template based on the post category? This tutorial shows how. Note:…
Categories:
Tags:
Pro
Outputting Only the First ACF Repeater Row in Bricks

Outputting Only the First ACF Repeater Row in Bricks

Updated on 12 Dec 2023 In the Bricks Facebook group a user asks: How can I display only the first entry from an ACF repeater?…
Pro
x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

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

Showing how to display one random row of a Meta Box group for an hour and then output another random row.
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"…
How to hide/remove the Block Element from the Bricks Builder

How to hide/remove the Block Element from the Bricks Builder

Don't like the new Block element in Bricks? Just copy/paste the following code into your child theme's functions.php. By the way, It's a terrible idea…
Categories:
Tags: