Title: Custom Fields &#8211; PHP If Statment
Last modified: August 19, 2016

---

# Custom Fields – PHP If Statment

 *  [Drew Baker](https://wordpress.org/support/users/dbaker/)
 * (@dbaker)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/custom-fields-php-if-statment/)
 * Hi,
    I’m trying to [follow the steps here](http://codex.wordpress.org/Function_Reference/get_post_custom_values)
   to display several thumbnails in my theme using customs fields.
 * I have it working now so it will display several custom fields with the name “
   image”. See my code here:
 *     ```
       <?php
   
       $mykey_values = get_post_custom_values('image');
       foreach ( $mykey_values as $key => $value ) {
       echo '<img src="'.$value.'">';
       }
       ?>
       ```
   
 * My problem is if there is no custom field with the “image” name then I get a 
   PHP error. How do I make this an if statement? Obviously my PHP skills are bad.
   Thanks!

Viewing 1 replies (of 1 total)

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/custom-fields-php-if-statment/#post-1240576)
 * try this
 *     ```
       <?php
       $mykey_values = get_post_custom_values('image');
       if ($mykey_values) {
         foreach ( $mykey_values as $key => $value ) {
           echo '<img src="'.$value.'">';
         }
       }
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Custom Fields – PHP If Statment’ is closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/custom-fields-php-if-statment/#post-1240576)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
