# Hiding empty fields

## Overview

It is a common task to hide empty field values from your template. This can be achieved by using conditional statements to check the value before rending it.

The basics to conditional a statement is to use an *if* statement. You can read more about this core PHP function here: <http://php.net/manual/en/control-structures.if.php>

## Examples

### Example 1: Basic

This example shows how to check for a value before displaying it. Please note the use of both [get\_field()](https://www.advancedcustomfields.com/resources/functions/get_field/ "get_field()") and [the\_field()](https://www.advancedcustomfields.com/resources/functions/the_field/ "the_field()").

```
<?php if( get_field('field_name') ): ?>
    <p>My field value: <?php the_field('field_name'); ?></p>
<?php endif; ?>
```

### Example 2: Loop

This example shows how the above methodology can be used within a loop. Please note the use of [get\_field\_objects()](https://www.advancedcustomfields.com/resources/functions/get_field_objects/ "get_field_objects()") to load the array.

```
<?php 

$fields = get_field_objects();

<?php if( $fields ): ?>
    <ul>
    <?php foreach( $fields as $field ): ?>

        <?php if( $field['value'] ): ?>
            <li><?php echo $field['label']; ?>: <?php echo $field['value']; ?></li>
        <?php endif; ?>

    <?php endforeach; ?>
    </ul>
<?php endif; ?>
```