This is fairly simple to achieve, first rename the name
attribute to my_categories[]
this is then passed as an array.
Then you will need set the values
of each checkbox as the category id
. In this way you can loop though the array my_categories[]
and then set the categories present in that array.
Here is a simplified example :
// In your callback function for metabox,
// This should be inside a loop.
term_id">
// In your callback function for metabox,
// This should be inside a loop.
<input type="checkbox" name="my_categories[]" value="$term->term_id">
<?php
// This should be hooked to the save_post action of appropriate post type.
if(!empty($_POST['my_categories'])) {
foreach($_POST['my_categories'] as $cat)
{
echo $cat;
//echoes the value set in the HTML form for each checked checkbox.
//In your case the ids of selected checkboxes, now all you need to do is set those categories.
}
}
?>
Now you have all the ids of selected categories in an array, which is easier to process. Use your logic to set the categories.