4th Oct '24
/
0 comments

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

Related Tutorials..

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
Filtering Bricks Query Loop By Meta Box Relationship

Filtering Bricks Query Loop By Meta Box Relationship

In the Bricks Facebook group a user asks: Consider this setup: CPTs: Service Areas and City Pages Meta Box Relationship: City Pages to Service Areas…
Categories:
Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Recently worked with a friend figuring out how to remove/undo/cancel an add_action() line that's inside a plugin's constructor inside a PHP Class with the file…
Categories:
Tags:
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.