Title: Custom fields / get_post_meta / get_the_id
Last modified: August 22, 2016

---

# Custom fields / get_post_meta / get_the_id

 *  [TheElear](https://wordpress.org/support/users/peterpap/)
 * (@peterpap)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-get_post-meta/)
 * Hello,
 * I think it must be pretty basic question but I am only starting. Can someone 
   have a look at the 3 versions of the same (?) code below and say what the difference
   is? All of them seem to work fine in the loop I am working on.
 * Which should be used: $post->ID, $the_ID or get_the_id()?
    Is it necessary to
   have global $post;?
 *     ```
       global $post;
       $content = get_post_meta( $post->ID, ‘my_custom_field', true );
       echo  $content;
       ```
   
 * or 
 *     ```
       $content = get_post_meta( $the_ID, ‘my_custom_field', true );
       echo  $content;
       ```
   
 * or 
 *     ```
       $content = get_post_meta( get_the_id(), ‘my_custom_field’, true );
       echo  $content;
       ```
   
 * Many thanks for your help

The topic ‘Custom fields / get_post_meta / get_the_id’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [TheElear](https://wordpress.org/support/users/peterpap/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-get_post-meta/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
