I have displayed a group field in block layout and sub fields before with get_field before but it isn’t working.
<code><?php $about = get_field("about"); ?>
<?php if ($about): ?>
<section>
<h2>About</h2>
<div>
<?php $description = get_field("description") ?>
<?php if ($description): ?>
<?php echo get_field("description"); ?>
<?php endif; ?>
<?php $location = get_field("location"); ?>
<?php if ($location): ?>
<?php echo get_field("location"); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
</code>
<code><?php $about = get_field("about"); ?>
<?php if ($about): ?>
<section>
<h2>About</h2>
<div>
<?php $description = get_field("description") ?>
<?php if ($description): ?>
<?php echo get_field("description"); ?>
<?php endif; ?>
<?php $location = get_field("location"); ?>
<?php if ($location): ?>
<?php echo get_field("location"); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
</code>
<?php $about = get_field("about"); ?>
<?php if ($about): ?>
<section>
<h2>About</h2>
<div>
<?php $description = get_field("description") ?>
<?php if ($description): ?>
<?php echo get_field("description"); ?>
<?php endif; ?>
<?php $location = get_field("location"); ?>
<?php if ($location): ?>
<?php echo get_field("location"); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
All that gets displayed is:
<code><section>
<h2>About</h2>
<div></div>
</section>
</code>
<code><section>
<h2>About</h2>
<div></div>
</section>
</code>
<section>
<h2>About</h2>
<div></div>
</section>
I was able to display them by doing this:
<code><?php $about = get_field("about"); ?>
<?php if ($about): ?>
<section>
<h2>About</h2>
<div>
<?php $description = $about["description"] ?>
<?php if ($description): ?>
<?php echo $about["description"]; ?>
<?php endif; ?>
<?php $location = $about["location"]; ?>
<?php if ($location): ?>
<?php echo $about["location"]; ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
</code>
<code><?php $about = get_field("about"); ?>
<?php if ($about): ?>
<section>
<h2>About</h2>
<div>
<?php $description = $about["description"] ?>
<?php if ($description): ?>
<?php echo $about["description"]; ?>
<?php endif; ?>
<?php $location = $about["location"]; ?>
<?php if ($location): ?>
<?php echo $about["location"]; ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
</code>
<?php $about = get_field("about"); ?>
<?php if ($about): ?>
<section>
<h2>About</h2>
<div>
<?php $description = $about["description"] ?>
<?php if ($description): ?>
<?php echo $about["description"]; ?>
<?php endif; ?>
<?php $location = $about["location"]; ?>
<?php if ($location): ?>
<?php echo $about["location"]; ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
But when the description and location fields are empty this is still displayed.
<code><section>
<h2>About</h2>
<div></div>
</section>
</code>
<code><section>
<h2>About</h2>
<div></div>
</section>
</code>
<section>
<h2>About</h2>
<div></div>
</section>
Should the about field display anything when it’s sub fields are empty?