Title: Insert text with Custom Fields ONLY when present
Last modified: August 19, 2016

---

# Insert text with Custom Fields ONLY when present

 *  [Gia Romano](https://wordpress.org/support/users/gentilessa/)
 * (@gentilessa)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/insert-text-with-custom-fields-only-when-present/)
 * hello there,
 * i have been trying to write code that will only display address information if
   that custom field is present. everytime i try to enter an “if” statement i get
   an error… I want the address and contact information to display only for a certain
   category and not for others.i currently have:
 *  <?php
    //Gets post-meta info
 *  if(get_post_meta($post_id, Course_Address, true);
    get_post_meta($post_id, Course_City,
   true); get_post_meta($post_id, Course_State, true); get_post_meta($post_id, Course_Postcode,
   true); get_post_meta($post_id, Course_Contact_Number, true); get_post_meta($post_id,
   Course_Holes, true); get_post_meta($post_id, Course_Length, true); get_post_meta(
   $post_id, Course_Par, true)) { ?> <p><b>Address: </b><?php echo get_post_meta(
   $post->ID, Course_Address, true); ?>, <?php echo get_post_meta($post->ID, Course_City,
   true); ?>, <?php echo get_post_meta($post->ID, Course_State, true); ?> <?php 
   echo get_post_meta($post->ID, Course_Postcode, true); ?> <b>Contact Number: </
   b><?php echo get_post_meta($post->ID, Course_Contact_Number, true); ?> <b>Holes:
   </b><?php echo get_post_meta($post->ID, Course_Holes, true); ?> <b>Length: </
   b><?php echo get_post_meta($post->ID, Course_Length, true); ?> <b>Par: </b><?
   php echo get_post_meta($post->ID, Course_Par, true); ?></p> <?php } ?>
 * This does not limit to categories, i imagine i will have to make a statement 
   like if category ” then get…?

The topic ‘Insert text with Custom Fields ONLY when present’ is closed to new replies.

## Tags

 * [get post meta](https://wordpress.org/support/topic-tag/get-post-meta/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Gia Romano](https://wordpress.org/support/users/gentilessa/)
 * Last activity: [17 years, 5 months ago](https://wordpress.org/support/topic/insert-text-with-custom-fields-only-when-present/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
