Forums

[resolved] [Plugin: PHP Code Widget] get post meta data not working in PHP Widget (2 posts)

  1. moongoose
    Member
    Posted 2 years ago #

    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/

  2. Otto
    Tech Ninja
    Posted 2 years ago #

    Add global $post; to the top of your code.

Topic Closed

This topic has been closed to new replies.

About this Topic