admin管理员组文章数量:1130349
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 badges1 Answer
Reset to default 0Late 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?
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 badges1 Answer
Reset to default 0Late 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?
本文标签: wp adminLimit post top level categories to one
版权声明:本文标题:wp admin - Limit post top level categories to one 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749121765a2319127.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论