This plugin currently provides you with the two functionalities mentioned above which you can enable/disable easily if you have KC Settings plugin installed. You can also modify the options using the available kcme_options filter (please read the FAQ section in the readme.txt file on how to do this).
The plugin is currently hosted at GitHub and will always be updated there, but it’s also in the process of approval to be hosted at WordPress plugin repo and I will update this post as soon as it’s approved and hosted there.
Enjoy the plugin and feel free to leave a comment/bug report/ideas in the comments section below 🙂
In WordPress, we can set multiple categories/terms for a post. This is true for both hierarchical taxonomies (ex: category) and non-hierarchical taxonomies (ex: post_tag). However, on a project I’ve worked on, the client wanted me to make the category metabox to use radio inputs (exactly like WordPress’ new post format feature) instead of checkboxes to prevent the editor from setting multiple categories for the post (s)he writes. This request forced me 🙂 to come up with a solution. I was also inspired by Justin Tadlock’s idea on using a taxonomy for theme layout. Here’s my solution in hope it could be useful for others.
As usual, you can either add this code to your theme’s function.php file or create a new php file for it and place it inside wp-content/mu-plugins directory (preferred) so you can always have this feature no matter what theme you’re using.
The first function — kc_unique_taxonomies — will find if you have set a taxonomy (or more) to be unique. You will have to add the taxonomy IDs using the available kc_unique_taxonomies filter hook (we’ll talk about it shortly). If there’s a unique taxonomy found, it will then remove the taxonomy’s default metabox in the post editing page, and replace it with the new one.
This function will only search for hierarchical taxonomies, because I strongly believe that a post should be allowed to have multiple non-hierachical taxonomy terms (ex: tags). Also, non-public and orphan taxonomies (taxonomies that are not attached to a post type) will be ignored.
The second function — kc_terms_radiolist — will display the replacement metaboxes for each unique taxonomies that use radio inputs for the taxonomy’s terms. I basically just took WordPress default category metabox and adjusted some parts of it.
The last step is to actually set some taxonomies to be unique which you can either do from your theme or plugin. Just add this snippet of code: