WordPress.org

Ready to get started?Download WordPress

Forums

Custom field in Sidebar - disappear if not (2 posts)

  1. Rob Cubbon
    Member
    Posted 2 years ago #

    Hey, this question isn't about 3.3!

    I'm trying to get a bit of text in the sidebar which is entered as a custom field on that particular page. To do this I installed PHP Code Widget plugin and put this in the widget:

    <?php global $wp_query;
    if(is_object($wp_query->queried_object) && $wp_query->queried_object->ID)
    {echo get_post_meta($wp_query->queried_object->ID, 'sidebar', true);}
    ?>

    Where "sidebar" is the custom field key.

    this works!

    My problem is that when there isn't a value for "sidebar" I would like the sidebar widget to not be there. At the moment I'm getting an empty box.

    I would like to do this with widgets if possible. I tried to use widget logic to get rid of the widget if there's no custom field value, but the code didn't work.

  2. edblume
    Member
    Posted 2 years ago #

    I don't understand. Where does the code go? I'm not a geek; I can only edit the CSS.

    With all of the posts about disappearing widgets, you'd think that WordPress would clearly explain how to make the widgets reappear. From all I can find, the Happiness Engineers never do.

    Blog URL - http://renewwisconsinblog.org

    Call me Unhappy Ed.

Topic Closed

This topic has been closed to new replies.

About this Topic