$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp admin - Limit post top level categories to one|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp admin - Limit post top level categories to one

matteradmin9PV0评论

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.

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.

Share Improve this question asked Aug 2, 2018 at 8:41 HazeHybridHazeHybrid 134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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?

Post a comment

comment list (0)

  1. No comments so far