WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ok Let's say I have 2 Categories. If a user select category A, they have to fill in metabox A and similarly for category B, it's metabox B. So my question is, I want to do a validate check, whereby if the user has checked category A, then it is only metabox A that has been filled in, and the same applies for category B. I know JQuery is my best bet - but not too sure how to go about it or how to call the function when clicking the publish button.

share|improve this question
Or even a way whereby if a category is selected it opens a metabox relevant to that category. – schizdazzle Mar 31 '11 at 9:44

Apologies for the delay - what I did was basically created a .js file and places it within my theme folder - for example themes/nameoftheme/custom/checkcode.js

Then using jquery - I created my code - here's a snippet:

jQuery('#in-category-3').attr('checked', this.checked);
jQuery('#in-category-1').attr('checked', false);
jQuery('#in-category-4').attr('checked', false);
jQuery('#in-category-5').attr('checked', false);
jQuery('#in-category-7').attr('checked', false);
jQuery('#in-category-8').attr('checked', false);
jQuery('#in-category-9').attr('checked', false)

It seems pretty explanatory but fyi in-category - refers to the category selected in the category box. attr - refers to attribute and as it's a checkbox - hence checked. when catgeory-6 is selected, the metaboxes defined by the name is either hidden or not.

After this - we now need to call this the javascript file - and this is done by going to the functions.php file of your theme.

here you put -

wp_enqueue_script('myscript', '/wp-content/themes/nameoftheme/custom/checkbox.js');

fyi wp_enqueue_script is the bit that calls the script when the page is loaded.

I hope this is clear for people.

share|improve this answer

I have found this plugin:


which has provided a good foundation and am going to attempt to hack it and take it from there.

share|improve this answer
Additional follow-up information should be added into the original question(unless you're providing the answer to your own question). – t31os Apr 1 '11 at 11:54
Great that you are on track to solve this problem on your own. If you can update this answer with a complete solution once you found it, that would be even better! – Jan Fabry Apr 5 '11 at 14:09

Every metabox has own ID.

We can handle onchange event of category checkboxes. Hide everything on load and then show, when user set a category.

share|improve this answer
I've got the jquery bit sorted - just a quick question, how I add the function to the add new post part... I am assuming it is to do with the add_action – schizdazzle Apr 1 '11 at 16:33
scratch my last comment this helped alot - planetozh.com/blog/2008/04/… – schizdazzle Apr 1 '11 at 17:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.