3rd Mar '26
/
0 comments

Outputting an Element in Bricks x times where x is a custom field value

In the Bricks Facebook group a user asks:

Hello folks, Is there a way to display an element x times where x is a number stored in a meta field?

Bricks 2.2 added a new new query type of Array and this can be used to display an element as many times as the value of a custom field.

Consider a custom field created with ACF named number_of_icons_to_display of type Number for the page post type.

For a specific Page, let's say the value for this is set to 6.

After implementing the code:

This Pro tutorial shows how this can be done.

Step 1

Create a custom function that returns an array of numbers from 1 to n where n is the meta value. This function can then be echoed for the Array query type to make the Icon be output 6 (in this example) times.

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

Related Tutorials..

HappyFiles Bricks Query Loop

HappyFiles Bricks Query Loop

This tutorial explores different ways in which images from WordPress Media Library organized via HappyFiles can be pulled and shown in Bricks using query loop(s).…
Categories:
Pro
Non-empty events sorted by event date and other posts below in Bricks

Non-empty events sorted by event date and other posts below in Bricks

Updated on 15 Jan 2024 Consider a scenario where you are showing posts from multiple post types namely post, event and game in a single…
Categories:
Pro
Bricks Query Loop – How to Insert Elements After Every Nth Post

Bricks Query Loop – How to Insert Elements After Every Nth Post

Update: Follow this tutorial instead. This Pro tutorial provides the steps to output element(s) in a Bricks' query loop after every nth post. Use case:…
Categories:
Pro
Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Updated on 29 Feb 2024 In the Sibling Terms Bricks Query Loop tutorial, a member asked: How can I set the class "active" to the…
Categories:
Pro
Mixed Post Types Grid in Bricks

Mixed Post Types Grid in Bricks

How to set up a mixed post types grid in Bricks, where you can display both standard posts and custom quote cards in alternating positions.
Categories: