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
}
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.