Home › Forums › Add-ons › Flexible Content Field › Show Empty Fields › Reply To: Show Empty Fields
just to understand:
and all that you wish is, when you didnt select/add the neck: you dont want to show neck?
that is what flexible field normally does. (add optional content-blocks, and show them only if needed. with that you can have required fields like a keyvisual a with title, but only when you add keyvisual-block)
what it does not do is: to look if a layout is already choosen 1 or more times, and if not display a alternate content.
if you really need that you need to set a variable inside the get_row_layout loop. also you had to put the values into a variable first. after all layout you check each variable and check if it is filled or not & set alternates
try if you can adapt this code
<?php
//define variables
$head= '';
$shoulder ='';
$neck ='';
//check for layouts and the values inside
if( have_rows('attach_files_multiple') ): while ( have_rows('attach_files_multiple') ) : the_row();
if( get_row_layout() == 'neck' ) :
$neck .= 'all about neck';
endif;
if( get_row_layout() == 'shoulder' ) :
$shoulder .= 'all about shoulder';
endif;
if( get_row_layout() == 'head' ) :
$head .= 'all about head';
endif;
endwhile; endif;
//check for filled values and build layout or the alternates
if ($head) {
echo $head;
} else {
echo 'no head was chosen ';
}
if ($shoulder) {
echo $shoulder;
} else {
echo 'no shoulder was chosen ';
}
if ($neck) {
echo $neck;
} else {
echo 'no neck was chosen ';
}
?>
why do you work with flexible fields when you replace anyway everything not filled with a default value?
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.