WAIT: ACF True/False fields in repeater in flexible content always return false

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

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.

The ACF field type “True / False” is great for conditional checks inside the element conditions. By default, the localized “True / False” label is returned. When using it in your element conditions, make sure to apply the :value filter. To check for false, you can compare against == 0 . Or == 1 to check for true.

So you should use {acf_page_sections_content_charlie_content_charlie_show_feature_counters:value}

Thanks for the reply. I did actually try that, but I forgot to include it in my original post. I can see the output of my function updates from 0 to 1 when I change the value, but regardless of whether the value is 0 or 1, the counter/element doesn’t show.

I guess we’ll never know if it’s a bug :laughing:

Hi @AaronChaos ,

Please may I know where you place the {acf_page_sections_content_charlie_content_charlie_show_feature_counters} when testing on a basic text element? You must place it inside the loop.

Additionally, you shouldn’t use have_rows() in Bricks because Bricks is not using that in the Flexible content query loop. You can retrieve the looping data via \Bricks\Helpers::get_loop_object(). You can var_dump it and you should be able to see the actual data.

Your problem 2 example is wrong in the logic because you don’t know which row you are currently in when executing bricks_check_content_charlie_feature_counters()

Kindly provide some screenshots of your structure so we can assist better. Best if you can record a video :slight_smile: