Home › Forums › Bug Reports › The Group field
Image field I have not inserted the image, the front page will still display the tag
<?php
// vars
$hero = get_field('hero');
if( $hero ): ?>
<div id="hero">
<img src="<?php echo $hero['image']['url']; ?>" alt="<?php echo $hero['image']['alt']; ?>" />
</div>
<?php endif; ?>
What did you get if you
<?php
echo "<pre>";
print_r($hero);
echo "</pre>";
?>
BTW: There’s one index to much echoing the $hero parameters:
<?php
// vars
$hero = get_field('hero');
if( $hero ): ?>
<div id="hero">
<img src="<?php echo $hero['url']; ?>" alt="<?php echo $hero['alt']; ?>" />
</div>
<?php endif; ?>
I got this code:
Array
(
[bathroom_projects_title] =>
[bathroom_projects_img] =>
[bathroom_projects_download_url] =>
)
I want all fields in the field group if there is no data, the front end does not output HTML
Do not show html <div id="hero">
…
It looks like your field hero
is a group field. If so try this
<?php
// vars
$hero = get_field('hero');
if( $hero ):
if( $hero['image'] ): >
<div id="hero">
<img />" alt="<?php echo $hero['image']['alt']; >" />
</div>
<?php endif; >
<?php endif; >
I think that the documentation for the group field may be a little off. @tmconnect’s code is correct. The group field acts similar to a repeater field that always has 1 row, even if none of the sub fields have content. You need to check for the value of the group field as well as checking the value of each sub field. If this is an issue I’d submit a new support ticket https://support.advancedcustomfields.com/new-ticket/
The topic ‘The Group field’ is closed to new replies.
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.