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

4 comments

Leave your comment

 

Related Tutorials..

Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories:
Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
[Function] Get Term Slug in Bricks

[Function] Get Term Slug in Bricks

If you are querying terms of a taxonomy (like category, post_tag or a custom one) using the awesome Query Loop feature of Bricks, there might…
Categories:
Pro
Testimonials Slider in Bricks

Testimonials Slider in Bricks

Setting up a dynamic testimonial slide that pulls the data from a CPT's post fields and custom fields.
Categories:
Tags:
Pro
Filtering ACF Relationship Query by Post Meta in Bricks

Filtering ACF Relationship Query by Post Meta in Bricks

How to filter the posts of a post type related to another post type based on the value of a True / False type ACF…
Pro
ACF Flexible Content Field – Layout Labels and Sub Field Labels

ACF Flexible Content Field – Layout Labels and Sub Field Labels

How to output the text of layout labels and/or sub field labels using the Flexible Content field of ACF Pro.
Categories: