I tried using radio button plugins like many suggest, but it ruins any functionality with ACF so keeping the checkboxes is essential.
In my example, which most code was adapted from jQuery checkbox change and click event & Make parent categories not selectable
In my functions.php I add actions for admin_footer-post and admin_footer-post-new (or else new posts wont be affected). I am sure you can add it to the header but don’t forget to update the jquery with a .ready()
Anyways, the code is really simple: If its a post, on change of a category checkbox remove all checked and apply the clicked check.
add_action( 'admin_footer-post.php', 'only_allow_one_checkbox' );
add_action( 'admin_footer-post-new.php', 'only_allow_one_checkbox' );
function only_allow_one_checkbox()
{
global $post_type;
if ( 'post' != $post_type )
return;
?>
<script type="text/javascript">
$('#categorychecklist>li>label input').change(function() {
if(this.checked) {
$('#categorychecklist>li>label input').prop("checked", false);
$(this).prop("checked", true);
}
});
</script>
<?php
}
So far, it was very easy to implement and have run into no issues.