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

Related Tutorials..

Pro
Post Data for the Current User in Bricks with Meta Box

Post Data for the Current User in Bricks with Meta Box

How to configure a query loop to output the post data of the SalesRep CPT associated with the current user.
Categories:
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
Pro
ACF User Field Bricks PHP Query

ACF User Field Bricks PHP Query

In the Bricks Facebook group a user asks: my end goal was to create a set of cards that would display the Users that are…
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…
Pro
Query Loop Index in Bricks

Query Loop Index in Bricks

This Pro tutorial provides the code for getting the index of each post in Bricks' query loops. This can be used for either outputting the…
Categories:
Pro
Child Posts Section in Bricks

Child Posts Section in Bricks

This Pro tutorial provides the steps to limit the posts (can be of any post type) output by Bricks' query loop to children of the…
Categories: