Problem
After realizing that post formats are pretty popular, but only a extremly rough drawn concept, i see that users will run into possible traps.
Post format …
- uses post meta fields & user doesn’t remember exact meta key name.
- takes the link/embed/whatever object from post editor & user inputs wrong data.
Both are examples of possible traps a user could hit.
Idea
The post format has a custom meta box that does only allow to input the expected data.
The idea itself isn’t that bad, but there’s still the problem that the user would have to
- put data into the correct meta box
- then select the according post format.
Question
What i’m searching for is
- a solution that switches (ajax) the meta box (or just its content) based on the selection a user makes inside the post formats meta box
OR…
- using a ajax/jquery-ui tabs inside the meta box to switch meta box contents and save the according post format on ‘save_post’
Note:
I’m not searching for the exact meta box content. My most interesst is to see the ‘surroundings’ in different code
examples.
Thank you!
I did something like this once, but when you clicked on a certain category (essentially the same) It certainly isn’t a true ajax solution, it just hides and reveals the div with the settings, but It is a solution which works. You’ll definitely have to modify this for your needs, but if you have a grasp on jQuery, I’m sure you’ll be able to modify this for your needs. If you are a little more specific about your needs, I’d be happy to edit this up to suit what you are looking for more exactly.
The Code:
I used this in a plugin, but you can just put this into your theme’s functions.php
Basically what you have here is a jQuery script that initially hides a meta box that I have already set up. The box’s ID is #testimonial-information. Then it checks on whether or not the specific category’s box is checked, and if it is, shows it. Then it listens for a click on the specific category’s box and toggles it’s visibility.
The Result:
A meta box that is visible only when the user has chosen a specific category. All you’ll need to do is set up your metaboxes and get all the ID’s of the elements you need. You’ll need the ID’s of the metaboxes as well as the checkboxes in question. Then all you need to do is follow this formula to get what you are looking for.
If you have everything set up but are having a hang-up writing the javascript, just provide me the ID’s of the metaboxes and corresponding checkboxes and I’d be more than happy to write it up for you.
This is the final javascript function. It should be hooked into
admin_footer
hook.