0

My website have many posts, ~9 main categories and "unlimited" subcategories.

I'd like to force in WordPress panel that you can't choose more than 1 top level category but you can choose unlimited subcategories of this main one.

One plugin changed checkboxes into radiobuttons and it works great but only for one level and I need more depth.

Is there any way to do that? Thanks in advance.

0

Late answer but I figured I'd throw in my idea since I had a similar problem recently.

Basically I did this by injecting a script into the editor views. My function looked something like this:

(function() {
    var o=function() {
    //add a click handler to category checkboxes
    jQuery("#categorychecklist input").click(function() {
        //get top-level category (in case child is checked)
        var tlc = jQuery("#category-all>ul>li").has(this);
        //if top-level category is not checked, check it
        jQuery(">label>input",tlc).prop("checked", true);
        //uncheck all boxes from other top-level categories
        jQuery("#category-all>ul>li").not(tlc).find("input:checked").prop("checked", false);
    });}
    //run this function onload
    var n=window.onload;"function"!=typeof window.onload?window.onload=o:window.onload=function(){n&&n(),o()};
})();

I hope this helps somebody. To add a script just use something like this: How to enqueue scripts on custom post add/edit pages?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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