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: jQuery('#in-category-6').click(function(){ 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. |
|||
|
|
|
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. |
|||||
|
|
I have found this plugin: http://wordpress.org/extend/plugins/require-post-category/ which has provided a good foundation and am going to attempt to hack it and take it from there. |
|||||
|