Set categories if checkbox selected


Hi, I’m new here and need some help.
I need to make automatical system that will set categories on every “custom post” if checkbox with id “first-box” is checked. It will be like:

if $id(first-box) true{ set default categories with id(10,15,21,25) }

Now i’m using on backend a script that works only on client side.
the code looks like:

$('#first-box').change(function(){ if (this.checked) { $('input:checkbox[id^="in-cat-10"]').attr('checked',true); $('input:checkbox[id^="in-cat-15"]').attr('checked',true); $('input:checkbox[id^="in-cat-21"]').attr('checked',true); $('input:checkbox[id^="in-cat-25"]').attr('checked',true); } })

And I think that code will be added on the function.php


You would be better off putting the code in a site specific plugin, that way on theme update or change your code will remain intact and functional.


it is… on the Custom CSS & JS. but it works only on fully load of backend page.
I need a new php code that will set that categories whenever post is added with that checkbox checked.

—Edited zone
I mean to set like the default category is setting up whenever an post is created. I think it must be like (add bonus id’s to the id colum on the DB)