WordPress allows Admin to select more than one category for a post , I would like to change that so user is allowed to select only 1 category for a custom post type.

Please note I cannot remove category selection box due to requirement of the project. Any help appreciated

1
1

Here’s the JS I use to replace checkboxes for radio buttons.

function checktoradio(){
    echo '<script type="text/javascript">jQuery("#categorychecklist-pop input, #categorychecklist input, .cat-checklist input").each(function(){this.type="radio"});</script>';
}

add_action('admin_footer', 'checktoradio');

This would also work for custom terms, you just need to find out the custom term ID used by inspecting the metabox element.

You would place this code inside functions.php. It basically adds a jquery script to the footer of the admin pages.

Disclaimer: I found the original code a long time ago on some website and adapted for my own use.

Leave a Reply

Your email address will not be published. Required fields are marked *