Support

Account

Home Forums Front-end Issues if statement issue subfields in group^field Reply To: if statement issue subfields in group^field

  • The ACF group field is a repeater field that always has one row. The value of the field will never be empty. There are several ways you can check this.

    
    // check each value in a loop;
    $values = get_field('total', $curauth);
    $empty = true;
    if (is_array($values)) {
      foreach ($values as $field_name => $value) {
        if ($value) {
          $empty = false;
          break;
        }
      }
    }
    if (!$empty) {
      //.....
    }
    
    
    // check using array_filter()
    $values = get_field('total', $curauth);
    $empty = true;
    if (is_array($values) && count(array_filter($values)) != 0) {
      $empty = false;
    }
    if (!$empty) {
     //...
    )