Home › Forums › Front-end Issues › Show an entire specific field group in frontend › Reply To: Show an entire specific field group in frontend
Hey Everyone! Glad this conversation is expanding.
I’ve run into a new problem with this code.
It seems like I can’t add conditions to this code within the main If statement, to not display if empty.
Here’s the issue. I have a header tag above this field group that I want to remove if there are no entries. I just can’t seem to get the code right.
Here’s what I have now:
$group_ID = 13249;
$fields = array();
$fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
if( $fields )
{
echo '<div class="col-sm-6">';
echo '<h3>Rates:</h3>'; //------I want to remove this line if field is empty, but it keeps appearing
echo '<ul class="list-unstyled">';
foreach( $fields as $field_name => $field )
{
$value = get_field( $field['name'] );
if ($field['choices']){
$map = array(
'yes' => '<i class="icon-ok"></i>'
);
$value = $map[ $value ];
} else {
}
if( $value && $value != 'no') {
echo '<li>' . $field['label'] . ' ' . $value . '</li>';
}
}
echo '</ul>';
echo '</div>';
}
So i need that h3 tag to not show up. What i found is that even when empty, the $fields variable sees an array (just echoing $fields shows ‘array’). So there is no way to say if ’empty’.
Thoughts?
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.