I’m trying to set up a sidebar area that’ll do two things:
- Display a drop-down of posts in a given custom post types.
- Display post metadata (content and custom fields) if selected post
The thing that’s getting me is two-fold:
- Having the selected post metadata display in the sidebar once selected via the dropdown
- Having the content refresh via ajax or jquery so it doesn’t refresh the entire page
What you are looking for is a bit involved but I wrote it anyway. Unfortunately it took longer than I planned so I’ve run out of gas on going in depth to explain it but I did document the code so hopefully that will help you follow it and you can download a copy of the code here.
The Widget in Use on the Website:
(source: mikeschinkel.com)
Note in my example I wrote a generic function to grab all the meta keys and meta values associated with a post to have something to display; that’s what you see on the screen.
The Widget Configuration in the Admin Console:
(source: mikeschinkel.com)
The Code
Here’s the code. This can be used in your theme’s
functions.php
file or as a standalone file in a plugin or theme you are developing:Also, if you want to read a good article about coding Widgets, Justin Tadlock has a good one called: