Title: Custom field with
Last modified: January 10, 2018

---

# Custom field with

 *  [janbrokes](https://wordpress.org/support/users/janbrokes/)
 * (@janbrokes)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-field-with/)
 * Hello,
 * I am using this code for displaying post custom field value
 * `<?php echo "Model: "; $key_name = get_post_custom_values($key = 'Model');echo
   $key_name[0]; ?>`
    and some others.
 * Sometimes post does not have all custom fields and there is displaying just text“
   ModeL:”
    How can I change the code above in order to display nothing when custom
   fields model is blank.

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

 *  [Muhammad Javed](https://wordpress.org/support/users/leadsoft/)
 * (@leadsoft)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-field-with/#post-9850803)
 * Hello
    you can use this function
 * echo “Model: “.get_post_meta(‘your-post-id-here’, ‘Model’, true);
    -  This reply was modified 8 years, 4 months ago by [Muhammad Javed](https://wordpress.org/support/users/leadsoft/).
 *  Thread Starter [janbrokes](https://wordpress.org/support/users/janbrokes/)
 * (@janbrokes)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-field-with/#post-9850810)
 * thanks for quick reply.
 * i need instead of ‘your-post-id-here use curent post id, beacuse it will be displayed
   on thousands of posts detail
 *  [Anh Tran](https://wordpress.org/support/users/rilwis/)
 * (@rilwis)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-field-with/#post-9851705)
 * To get the current post ID, you can use function `get_the_ID()`. So the code 
   is:
 * `echo 'Model: ', get_post_meta( get_the_ID(), 'Model', true );`
 * By the way, if you need a better way to create custom fields, there’s a plugin
   [Meta Box](https://metabox.io) that can help you a lot.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/custom-field-with/#post-9853023)
 * you can aslo check if the field is filled in before you output:
 *     ```
       <?php $key_name = get_post_custom_values($key = 'Model');
       if( $key_name[0] ) { echo "Model: "; echo $key_name[0]; } ?>
       ```
   

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

The topic ‘Custom field with’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 4 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/custom-field-with/#post-9853023)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
