Checking for ACF Repeater Rows in Bricks

Bricks enables us to conditionally output elements if a basic ACF field type like Text has value by selecting it in the Dynamic data condition with != and leaving the value input empty.

With the above condition applied, the element will only be output if the custom field named header_notice created with ACF is not empty.

What about the case when the field type is a little more complex one (that returns an array) like the ACF Repeater?

We need to define a custom function that returns either true (1) or false (0) and check against = 1 (to check if not empty) or ! = 1 (to check if empty).

Add the following in child theme‘s functions.php or a code snippets plugin:

// Function to check if the given ACF Repeater field has any rows of data.
function bl_have_rows( $field ) {
  // if ACF is not active, return false
  if ( ! class_exists( 'ACF' ) ) {
    return false;
  }

  return get_field( $field ) ? true : false;
}

and use it like this:

{echo:bl_have_rows(site_builders)}

Replace site_builders with the name of your ACF Repeater’s field name.

With the above condition in place, the Section will be output only if a ACF Repeater having a field name of site_builders has at least 1 row of data.

Instant access to all 250+ Bricks code tutorials with BricksLabs Pro

Leave the first comment