Support

Account

Home Forums General Issues Hide Empty Group Field Reply To: Hide Empty Group Field

  • A group field is a repeater field that always has 1 row. if(have_rows('group_field')) will always return true and get_field('group_field) will always return a non-empty array. You actually need to check each sub field.

    
    // loop
    while (have_rows('large_service')) {
      the_row();
      if (get_sub_field('background_image')) {
        $image = get_sub_field('background_image');
        ?>
          <div class="col-50">
            <div class="promo" style="background-image: url(<?php 
                echo $image['url']; ?>);">
              Content
    	</div>
          </div>
        <?php 
      }
    }
    
    
    // array
    $servicel = get_field('large_service');
    if ($service1['background_image'])) {
      ?>
        <div class="col-50">
          <div class="promo" style="background-image: (<?php 
              echo $service1['backgroud_image']['url']; ?>);">
            Content
          </div>
        </div>
      <?php 
    }