Support

Account

Home Forums General Issues when value is empty it shows lable name

Solved

when value is empty it shows lable name

  • hi, im using this code to show the label and its value :

    <?php
    $field = get_field_object('sors');
    ?>
    <p><?php echo $field['label'] ?>: <?php echo $field['value'] ?></p>	

    but when you don’t want to fill the value, it shows the field label

    how to solve it to don’t show the field label when its value is empty ??

  • Hi Javadth,

    If you want to echo the label (and the value) only if $field[‘value’] is not empty you can do this way :

    <?php
    $field = get_field_object('sors');
    $value = $field['value'];
    if (!empty($value)){
        echo '<p>'.$field['label'].' : '.$value.'</p>';
    }
    ?>

    Hope it’s help.

  • thanq @feyfey

    now if i wanna put a <br> or <p> between the label and value what should i do ?

  • Hi Javadth,

    Sorry for the delay. You can add simply a <br> the way below:

    <?php
    $field = get_field_object('sors');
    $value = $field['value'];
    if (!empty($value)){
        echo '<p>'.$field['label'].' : <br> '.$value.'</p>';
    }
    ?>
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘when value is empty it shows lable name’ is closed to new replies.