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.
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:
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.
here you put -
fyi wp_enqueue_script is the bit that calls the script when the page is loaded.
I hope this is clear for people.
I have found this plugin:
which has provided a good foundation and am going to attempt to hack it and take it from there.
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.