Support

Account

Home Forums Front-end Issues do not show the field if it is empty

Helping

do not show the field if it is empty

  • hi, I need to make sure that the field is not shown if it is not filled

    <?php
    $field_name = "zone";
    $fields = get_field($field_name);
    
    if($fields){
        echo '<div class="col-xs-4 col-lg-3"><strong>' . $field['label'] . ':' . '</strong></div>';
        echo '<div class="col-xs-8 col-lg-9">';
        foreach ($fields as $field){
    	    echo $field['value'] . ', ';
        }
        echo '</div>';
    }
    ?>

    all to what I can think of it

    <?php
    $field_name = "zone";
    $fields = get_field($field_name);
    
    if($fields){
        echo '<div class="col-xs-4 col-lg-3"><strong>' . $field['label'] . ':' . '</strong></div>';
        echo '<div class="col-xs-8 col-lg-9">';
        foreach ($fields as $field){
    	    echo $field['value'] . ', ';
        }
        echo '</div>' 
     else {
    
        echo 'empty';
    }
    ?>

    but that’s not it, I need to completely hide the line if the field is not full

  • Hi @relokate

    Thanks a bundle for the mail.

    Your setup is slightly confusing, wnat is the field type of the ‘zone’ field?

    Why are you looping the $fields value? Kindly do a var_dump of the ‘zone’ field value and let me know what is returned when empty.

    Kindly explain to me more so that I may be able to advise further.

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

You must be logged in to reply to this topic.