Title: Conditional custom fields
Last modified: August 19, 2016

---

# Conditional custom fields

 *  [bheinks](https://wordpress.org/support/users/bheinks/)
 * (@bheinks)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/conditional-custom-fields/)
 * Alright, so the website for my high school journalism program has custom fields
   for the writer’s name and their corresponding job title. Here’s the code to display
   them in posts:
 * `<?php $writer = get_post_meta($post->ID, writer, true); $jobtitle = get_post_meta(
   $post->ID, jobtitle, true); if ($writer) { ?><?php echo $writer; if ($jobtitle){?
   >, <?php echo $jobtitle; }} ?>`
 * It comes out to look like this: “Writer, Jobtitle”. I’d like for these to be 
   conditional with the word “None” for when the post lacks a writer/jobtitle. How
   could I achieve this? Thanks in advance.

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/conditional-custom-fields/#post-1849738)
 * Try:
 *     ```
       <?php
       $writer = get_post_meta($post->ID, writer, true);
       $jobtitle = get_post_meta($post->ID, jobtitle, true);
       if ($writer) echo $writer;
       else echo 'None';
       if ($jobtitle) echo $jobtitle;
       else echo 'None';
       ?>
       ```
   
 *  Thread Starter [bheinks](https://wordpress.org/support/users/bheinks/)
 * (@bheinks)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/conditional-custom-fields/#post-1849916)
 * That did the trick. Thank you very much.

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

The topic ‘Conditional custom fields’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [bheinks](https://wordpress.org/support/users/bheinks/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/conditional-custom-fields/#post-1849916)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
