Custom field in Sidebar – disappear if not
-
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.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom field in Sidebar – disappear if not’ is closed to new replies.