Title: Conditional statement using Custom Fields
Last modified: August 20, 2016

---

# Conditional statement using Custom Fields

 *  [caesarg](https://wordpress.org/support/users/caesarg/)
 * (@caesarg)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-using-custom-fields/)
 * I have a pretty simple question, but cant for the life of me work it out.
 * So I have two custom fields.
 * One is thumbnail_ID_URL1, the other is thumnail_ID_URL2.
 * Now, when posting, I either use one or the other, never both.
 * I need to display the thumbnail in the loop.
 * So I need a statement that is basically…
 * If custom field thumbnail_ID_URL1 has a value,
    <img src=”[http://blah.com/<thumbnail_ID_URL1&gt](http://blah.com/<thumbnail_ID_URL1&gt);.
   jpg>
 * else
 * If custom field thumbnail_ID_URL2 has a value,
    <img src=”[http://meh.com/<thumbnail_ID_URL2&gt](http://meh.com/<thumbnail_ID_URL2&gt);.
   jpg>
 * else
 * <img src=”[http://myurl.com/default.jpg&gt](http://myurl.com/default.jpg&gt);
 * —
 * Any ideas?

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-using-custom-fields/#post-2309906)
 * This is UNTESTED, but should be close:
 *     ```
       <?php
       $url1 = get_post_meta($post->ID,'thumbnail_ID_URL1',true);
       $url2 = get_post_meta($post->ID,'thumbnail_ID_URL2',true);
       if ($url1) {
          $src = "http://blah.com/$url1.jpg";
       } elseif ($url2) {
          $src = "http://meh.com/$url2.jpg";
       } else {
          $src = 'http://myurl.com/default.jpg';
       }
       ?>
       <img src="<?php echo $src; ?>" />
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Conditional statement using Custom Fields’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/conditional-statement-using-custom-fields/#post-2309906)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
