WIP: Conditions (UI) does not work on ACF repeater fields or sub fields

I cannot get conditions to work when targeting an ACF repeater field (row) or an ACF sub field.

Targeting the native WP custom field works, ala; {cf_sh_avstander} instead of {acf_sh_avstander}.

See attached image. For illustration purposes, I’ve set them both up, but only the top one actually works.

Hi Stein,
Thanks so much for your report!

Which version are you currently using? Please edit your report and add the version number.

However, I was able to reproduce the issue. Checking the ACF repeater values requires using the ACF have_rows() function, so comparing to empty, null or similar doesn’t work in this case.

Best regards,
timmse

3 Likes

Hey Stein,
Quick question: do you query the ACF repeater with a loop on the page? If not, you should try that. Then the conditions should work :v:

Hello timmse,

Thank you for looking into it.
I’m not sure I understand what you mean :no_mouth: Could you elaborate?

Stein

I thought we can check repeater field like that too, but apparently not:

To be able to use the ACF repeater values, you must query them with a query loop, otherwise they are not available and therefore cannot be used in the conditions. This is our variant of the ACF have_rows() function.

So: Add an ACF Repeater query loop so that the entries are queried and accordingly available, and test the condition again.

Note, the solutions provided do not work for nested repeaters in my current situtation.

I have:

  • Parent repeater loop
    • DIV wrapper
      • Nested repeater

I wanted to apply the conditional statement to the “DIV wrapper”. I cannot set this as a query loop, as suggested.

I tried a bunch of stuff, and eventually tried this:

/*
 *   Check if nested ACF repeater has fields
 *
 *   @access public
 *   @param string $parent Parent repeater field slug
 *   @param string $child Child repeater field slug
 *   @return boolean True if repeater has rows
 */
function custom_acf_nested_repeater_check($parent, $child)
{
    // if ACF is not active, return false
    if (!class_exists("ACF")) {
        return false;
    }
    // Bricks loop index, to simulate ACF row
    $row = intval( Bricks\Query::get_loop_index() ) + 1;
    
    if (have_rows($parent)):
        while (have_rows($parent)):
            the_row();
            // ACF row index
            $subRow = get_row_index();
            
            // Check and return true if nested repeater has fields
            if (($subRow === $row) && have_rows($child)):
                return true;
                break;
            endif;
        endwhile;
    endif;
    
    return false;
}

This does not work with the conditional feature within Bricks, I have no idea why.