Support

Account

Home Forums Front-end Issues Show an entire specific field group in frontend Reply To: Show an entire specific field group in frontend

  • Hey Everyone! Glad this conversation is expanding.
    I’ve run into a new problem with this code.

    It seems like I can’t add conditions to this code within the main If statement, to not display if empty.

    Here’s the issue. I have a header tag above this field group that I want to remove if there are no entries. I just can’t seem to get the code right.
    Here’s what I have now:

      $group_ID = 13249;
    $fields = array();
    $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    
    if( $fields )
    {
    echo '<div class="col-sm-6">';
    echo '<h3>Rates:</h3>'; //------I want to remove this line if field is empty, but it keeps appearing
        echo '<ul class="list-unstyled">';
      foreach( $fields as $field_name => $field )
      {
        $value = get_field( $field['name'] );
        if ($field['choices']){
          $map = array(
           'yes' => '<i class="icon-ok"></i>'       
           );
          $value = $map[ $value ];
        } else {
        }
        if( $value && $value != 'no') {
          echo '<li>' . $field['label'] . '&nbsp;' . $value . '</li>';
      }
    }
      echo '</ul>';
    echo '</div>';
    }

    So i need that h3 tag to not show up. What i found is that even when empty, the $fields variable sees an array (just echoing $fields shows ‘array’). So there is no way to say if ’empty’.

    Thoughts?