Support

Account

Home Forums Front-end Issues Display label and value only if value entered

Solved

Display label and value only if value entered

  • i currently have the following:

    <?php
    $field_name = "text_field";
    $field = get_field_object($field_name);   
    ?>
    
    <table>
        <tbody>
        <?php
        if( isset($field['value'] ): ?> 
            <tr>
                <th><?php echo $field['label']; ?></th>
                <td><?php echo $field['value']; ?></td>
            </tr>
        <?php endif; ?>
        </tbody>
    </table>

    my goal is to make the entire table row collapse and not display if there is no value entered.

    clearly a novice. thanks for taking a look.

  • field[‘value’] will always be set.

    Instead do if (!empty($field['value']) or just if ($field['value']) either should work.

  • thanks johnny boy! you’ve done it 🙂

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

The topic ‘Display label and value only if value entered’ is closed to new replies.