Support

Account

Home Forums Bug Reports The Group field

Solved

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/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.