Home › Forums › Add-ons › Flexible Content Field › Hide flexible content is all fields are empty › Reply To: Hide flexible content is all fields are empty
You’d need to check every field. I would probably do something like
$sub_fields = array(
'create',
'an',
'array',
'of',
'sub_field',
'names',
);
if (have_rows('flex_field')) {
while (have_rows('flex_field')) {
the_row();
$has_content = false;
foreach ($sub_fields as $sub_field()) {
if (get_sub_field($sub_field)) {
// flex field has content
$has_content = true;
// do not need to continue loop once you find content
break;
} // end if get sub field
} // end foreach sub field
if (!$has_content) {
// this layout has no content
// skip it
continue;
} // end if !content
// *********************************************
// code to display layout here
// *********************************************
} // end while have rows
} // end if have rows
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.