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

4 comments

Leave a Reply to Simon Pheasey (Cancel Reply)

 

Related Tutorials..

Pro
Filtering Query Loop Posts by a Non-empty Custom Field in Bricks

Filtering Query Loop Posts by a Non-empty Custom Field in Bricks

This Pro tutorial shows how we can prefilter the results of a query output by a Bricks query loop to only those for which the…
Categories:
Tags:
ACF Relationship: Count of Related Posts

ACF Relationship: Count of Related Posts

Looking to get the number of CPT B posts related to a CPT A post when using a Relationship field with ACF? Here's a custom…
Categories:
Tags:
Pro
ACF Term Meta on Single Posts in Bricks

ACF Term Meta on Single Posts in Bricks

Consider this scenario: CPT: Project Custom taxonomy: Project Type Each project will be assigned only one project type. Project Type taxonomy's custom field: Project Type…
Categories:
Pro
Related Posts using ACF Post Object in Bricks

Related Posts using ACF Post Object in Bricks

Modifying the query loop to limit the posts to only related posts via an ACF Post Object custom field.
Categories:
Tags:
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:
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: