Yep, doesn’t work for me as well. If all fields are empty it still generates HTML markup to hold the content. Running latest version of both.
*edit: Actually just looking into this more, it only seems to be with Repeater fields. Is that the case for anyone else?
Code examples:
This works:
<?php if(get_field("cabinet_or_party_leader")) : ?>
<p class="cabinet-or-party"><span><?php the_field( "cabinet_or_party_leader" ); ?></span></p>
<?php endif; ?>
This doesn’t work:
<?php
if(have_rows('family_information')) : ?>
<hr>
<h4>Family</h4>
<table class="info-table">
<tbody>
<?php while( have_rows('family_information') ): the_row() ; ?>
<?php if(get_sub_field('marital_status')) : ?>
<tr>
<td class="title">Marital Status:</td>
<td><?php the_sub_field('marital_status') ?></td>
</tr>
<?php endif; ?>
<?php if(get_sub_field('spouse_name')) : ?>
<tr>
<td class="title">Spouse Name:</td>
<td><?php the_sub_field('spouse_name') ?></td>
</tr>
<?php endif; ?>
<?php if(get_sub_field('spouse_occupation')) : ?>
<tr>
<td class="title">Spouse Occupation:</td>
<td><?php the_sub_field('spouse_occupation') ?></td>
</tr>
<?php endif; ?>
<?php if(get_sub_field('children')) : ?>
<tr>
<td class="title">Children:</td>
<td>
<ul class="blank-list">
<?php while( have_rows('children_details') ): the_row() ; ?>
<li>
<?php if(get_sub_field('child_name')) the_sub_field('child_name') ?><?php if(get_sub_field('child_name') && get_sub_field('child_age') || get_sub_field('note')) echo ', ' ?><?php if(get_sub_field('child_age')) echo get_sub_field('child_age') ?><?php if(get_sub_field('child_age') && get_sub_field('note')) echo ', ' ?><?php if(get_sub_field('note')) the_sub_field('note') ?>
</li>
<?php endwhile; ?>
</ul>
</td>
</tr>
<?php endif; ?>
<?php if(get_sub_field('relations')) : ?>
<tr>
<td class="title">Relations:</td>
<td>
<ul class="blank-list">
<?php while( have_rows('relations_details') ): the_row() ; ?>
<li>
<?php if(get_sub_field('relation_name')) the_sub_field('relation_name') ?><?php if(get_sub_field('relation_name') && get_sub_field('relation_age') || get_sub_field('note')) echo ', ' ?><?php if(get_sub_field('relation_age')) the_sub_field('relation_age') ?><?php if(get_sub_field('relation_age') && get_sub_field('note')) echo ', ' ?><?php if(get_sub_field('note')) the_sub_field('note') ?>
</li>
<?php endwhile; ?>
</ul>
</td>
</tr>
<?php endif; ?>
<?php endwhile; ?>
</tbody>
</table>
<?php endif; ?>
and still outputs this html:
<h4>Family</h4>
<table class="info-table">
<tbody>
</tbody>
</table>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.