Setting element condition in Bricks Builder based on ACF repeater sub field value

Step 1

Add the following function in theme’s functions.php file. The function accepts two arguments: $field (repeater field name) and $sub_field (repeater field’s sub field). It checks if the sub field is empty or not and returns true (1) or false (0) accordingly.

// Check if a subfield of ACF repeater field is empty or not

function check_acf_repeater_subfield( $field , $sub_field ) {
	
	if ( ! class_exists( 'ACF' ) ) {
		return false;
	}

	if( have_rows( $field ) ):
	
    while( have_rows( $field ) ) : the_row(); // Two ACF functions to loop through acf repeater field
	return get_sub_field( $sub_field ) ? true : false; // get_sub_field() is ACF function to get value from the repeater field's sub field
    endwhile;
	
	else :
		
	endif;
}
Step 2

Add the following condition in Bricks Builder element:

Condition: Dynamic Data
Select Dynamic Data: {echo:check_acf_repeater_subfield(repeater_field_name , repeater_sub_field_name)}
Condition: ==
Value: 1

Similar Posts