Browser: Firefox 145.0b2
OS: macOS
ACF True/False fields inside Flexible Content layouts cannot be properly evaluated in Bricks conditions, even when inside a Flexible Content query loop. Additionally, using ACF’s have_rows() and the_row() inside custom functions called from Bricks Query Loops causes loop interference.
Setup
I am using ACF with the following structure:
- Flexible Content field:
page_sections - Layout:
content_charlie- True/False field:
content_charlie_show_feature_counters - Repeater field:
content_charlie_features
- True/False field:
In Bricks, I have a block set to query loop that queries page_sections. Within the block, I have sections dynamically shown with conditions, for example:
- Dynamic data
{acf_get_row_layout}==content_charlie
This condition works perfectly.
Problem 1: True/False field always returns false
Inside content_charlie, I have a counter element with this condition:
- Dynamic data
{acf_page_sections_content_charlie_content_charlie_show_feature_counters}==1
This doesn’t work. When I output {acf_page_sections_content_charlie_content_charlie_show_feature_counters} as text, it always displays false, regardless of whether the field is checked or unchecked. In the database, the value is updated correctly from 0 to 1.
Problem 2: Custom function with have_rows() causes loop interference
I created a custom function to work around the issue:
function bricks_check_content_charlie_feature_counters() {
$post_id = get_the_ID();
if (have_rows('page_sections', $post_id)) {
while (have_rows('page_sections', $post_id)) {
the_row();
if (get_row_layout() === 'content_charlie') {
$value = get_sub_field('content_charlie_show_feature_counters');
return $value ? "1" : "0";
}
}
}
return "0";
}
When calling {echo:bricks_check_content_charlie_feature_counters} from within a nested repeater query loop (for content_charlie_features), the function returns alternating values (1, 0, 1, 0) instead of consistent values:
Row 1: 1 (call #1)
Row 2: 0 (call #2)
Row 3: 1 (call #3)
Row 4: 0 (call #4)
Working Solution
Using get_field() to retrieve the array and foreach instead of have_rows() fixes the interference:
function bricks_check_content_charlie_feature_counters() {
$page_sections = get_field('page_sections', get_the_ID());
if (!$page_sections || !is_array($page_sections)) {
return "0";
}
foreach ($page_sections as $section) {
if (isset($section['acf_fc_layout']) && $section['acf_fc_layout'] === 'content_charlie') {
$value = isset($section['content_charlie_show_feature_counters']) ? $section['content_charlie_show_feature_counters'] : false;
return $value ? "1" : "0";
}
}
return "0";
}
With this version, using the condition:
- Dynamic data
- {echo:bricks_check_content_charlie_feature_counters}
- ==
- 1
Works correctly and shows/hides the element as expected.