Title: Problem with post_ID
Last modified: August 20, 2016

---

# Problem with post_ID

 *  Resolved [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_id/)
 * Hi guys
 * I am trying to get the [PHP code widget](http://wordpress.org/extend/plugins/php-code-widget/)
   to do something very simple – echo the value of a custom field on a per-post 
   basis.
 * In post #553, I’ve defined custom field “_foobarbaz_” with value “_garply_“.
 * In my PHP code widget, I have:
 * <?php echo get_post_meta($post->ID, ‘foobarbaz’, true); ?>
 * …nothing.
 * I’ve also tried (the post ID is 553)
 * <?php echo get_post_meta(‘553’, ‘foobarbaz’, true); ?>
 * That works. Is there any way I can figure out why it’s not picking up the post
   number?

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_id/#post-2163357)
 * try to put `global $post;` before the `echo`:
 *     ```
       <?php global $post; echo get_post_meta($post->ID, 'foobarbaz', true); ?>
       ```
   
 *  Thread Starter [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_id/#post-2163365)
 * Works a charm, thank you!

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

The topic ‘Problem with post_ID’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_id/#post-2163365)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
