27th Oct '22
/
4 comments

Accessing ACF Repeater Sub Fields Programmatically in Bricks Query Loop

It is possible to output sub field’s values when a Bricks query loop’s type has been set to a ACF Repeater without writing code. This is built-in.

If you are looking to get/output the sub field’s value via code instead, simply using the_sub_field() or get_sub_field() is not going to work [unless we loop through the entire have_rows()].

Here’s how the sub field values can be output in a Code element:

<?php

// get the current row in the loop
$acf_row = \Bricks\Query::get_loop_object();
// print_r( $acf_row );

echo $acf_row['details']; 

?>

Given

and

and

for example, sample output of

print_r( $acf_row );

is:

Array ( [name] => Head Massage [details] => Dolor tempor irure irure aute pariatur. Aliqua mollit cillum ad elit. Elit aliquip fugiat reprehenderit incididunt deserunt. Aliqua qui magna amet proident fugiat ut exercitation exercitation enim sunt velit incididunt pariatur. )

Source: https://forum.bricksbuilder.io/t/acf-repeater-get-sub-field-not-working/7281

Get access to all 626 Bricks code tutorials with BricksLabs Pro

4 comments

Leave a Reply to Sridhar Katakam (Cancel Reply)

 

Related Tutorials..

Pro
Featured Image’s Meta in a Bricks Posts Query Loop

Featured Image’s Meta in a Bricks Posts Query Loop

How to output values of custom fields for the featured image of current post in a query loop
Categories:
Tags:
Pro
How to Update Custom Fields with Default Values For Existing Posts when using ACF

How to Update Custom Fields with Default Values For Existing Posts when using ACF

Let's take a scenario where there are 10 Pages in a WordPress site. You proceed to create a Text-type of custom field called, say, "Custom…
Categories:
Tags:
ACF Repeater Sub Field Values as Tabs in Bricks

ACF Repeater Sub Field Values as Tabs in Bricks

Bricks' query loop supports ACF Repeaters and Meta Box Groups out of the box besides posts, users and terms. This tutorial shows how we can…
Categories:
Tags:
Pro
Querying Posts by Date/Datetime Custom Fields in Bricks

Querying Posts by Date/Datetime Custom Fields in Bricks

This Pro tutorial shows how to configure ACF and Meta Box to query posts in Bricks by custom field(s) of the type Date/Date Time Picker…
Categories:
Tags:
Color Custom Field as Section Background Color on Category/Term Archives in Bricks

Color Custom Field as Section Background Color on Category/Term Archives in Bricks

How to use a color from a taxonomy term custom field for as the hero section background color on archive pages.
Categories:
Tags:
Pro
Outputting ACF Repeater’s Sub Fields

Outputting ACF Repeater’s Sub Fields

This Pro tutorial provides the code for printing custom HTML after looping through rows of a ACF Repeater (available in ACF Pro) that has a…
Categories: