Title: [Plugin: PHP Code Widget] get post meta data not working in PHP Widget
Last modified: August 19, 2016

---

# [Plugin: PHP Code Widget] get post meta data not working in PHP Widget

 *  Resolved [moongoose](https://wordpress.org/support/users/moongoose/)
 * (@moongoose)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-get-post-meta-data-not-working-in-php-widget/)
 * Hi,
 * I can insert the following code in my sidebar.php file:
 *     ```
       <?php $sidebar = get_post_meta($post->ID, 'Sidebar', $single = true); ?>
       <?php if($sidebar !== '') { ?>
       <?php echo $sidebar; ?>
       <?php } else { echo ''; } ?>
       ```
   
 * And the values in my Sidebar custom field display. But when I insert this code
   into the PHP widget instead, it simply does not get the post meta data. Any ideas
   what I’m doing wrong?
 * [http://wordpress.org/extend/plugins/php-code-widget/](http://wordpress.org/extend/plugins/php-code-widget/)

Viewing 1 replies (of 1 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [16 years, 3 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-get-post-meta-data-not-working-in-php-widget/#post-1360772)
 * Add `global $post;` to the top of your code.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: PHP Code Widget] get post meta data not working in PHP Widget’
is closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-get-post-meta-data-not-working-in-php-widget/#post-1360772)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
