Support

Account

Home Forums Front-end Issues Hiding empty fields

Helping

Hiding empty fields

  • Hey guys. I am having a lot of troubles with hiding my empty fields. Using:
    <?php the_meta(); ?> is perfect for me, it print’s out what i need. However, it also displays Everything when there is tothing in it.

    I don’t wan’t a field labbel to show, when there is no actual value in it.
    I tried with the examples here: http://www.advancedcustomfields.com/resources/hiding-empty-fields/ – bit it just crashed my site.

    This here will display all the data ass needed, but won’t sort out empty fields..
    I hope you wanøt to help

    <?php 
    $fields = get_field_objects();
    
    if( $fields )
    {
    	foreach( $fields as $field_name => $field )
    	{
    		echo '<div>';
    			echo '<h3>' . $field['label'] . '</h3>';
    			echo $field['value'];
    		echo '</div>';
    	}
    }
    
    ?>
  • 
    <?php 
        $fields = get_field_objects();
        if ($fields) {
            foreach($fields as $field_name => $field) {
                if ($field['value']) {
                    echo '<div>';
                    echo '<h3>' . $field['label'] . '</h3>';
                    echo $field['value'];
                    echo '</div>';
                } // end if field value
            } // end foreach fields
        } // end if fields
    ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Hiding empty fields’ is closed to new replies.