Title: Custom fields with if else conditionals
Last modified: August 19, 2016

---

# Custom fields with if else conditionals

 *  Resolved [fortkentgent](https://wordpress.org/support/users/fortkentgent/)
 * (@fortkentgent)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/custom-fields-with-ifelse-conditionals/)
 * Hopefully somebody can assist me because I’m having no luck. I’m not an experienced
   coder but I’d really like to accomplish this. I want to link the title of my 
   posts to external sources and I hope to use a conditional+custom field to do 
   this. The custom field key is titled “source” and the value will be a url. So
   id like to say..
 *     ```
       IF source (the key of my custom field)
   
       url (the value of my custom field)
   
       ELSE
   
       <?php the_permalink() ?>
       ```
   
 * Could somebody please give me some help?

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

 *  Thread Starter [fortkentgent](https://wordpress.org/support/users/fortkentgent/)
 * (@fortkentgent)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/custom-fields-with-ifelse-conditionals/#post-806175)
 * Sorry to bump but I can’t figure this out. This is what I have but I get errors
   and I’m basically clueless.
 *  `<?php if (get_post_meta($post->ID, ‘source’, true) ) {
    <h1>ID, “source”, $
   single = true); ?>” rel=”external” title=”External Link to <?php the_title();?
   >”><?php the_title(); ?>
   </h1>
    } else { <h1>” rel=”bookmark” title=”Permanent
   Link to <?php the_title(); ?>”><?php the_title(); ?></h1> } ?>`
 *  Thread Starter [fortkentgent](https://wordpress.org/support/users/fortkentgent/)
 * (@fortkentgent)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/custom-fields-with-ifelse-conditionals/#post-806176)
 * I got it.
 *     ```
       <?php if (get_post_meta($post->ID, 'source', true) ) { ?>
       				<h1><a href="<?php echo get_post_meta($post->ID, "source", $single = true); ?>" rel="external" title="External Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
       				<?php } else { ?>
                       <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
       				<?php } ?>
       ```
   
 *  [subiectiv](https://wordpress.org/support/users/subiectiv/)
 * (@subiectiv)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/custom-fields-with-ifelse-conditionals/#post-806413)
 * thanks man, i tried almost five days to make that thing work. of course, in some
   other circumstances, but it worked. you rule 🙂

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

The topic ‘Custom fields with if else conditionals’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)

 * 3 replies
 * 2 participants
 * Last reply from: [subiectiv](https://wordpress.org/support/users/subiectiv/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/custom-fields-with-ifelse-conditionals/#post-806413)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
