Site icon WebDevStudios

How to Replace WordPress Default Taxonomy Metabox with a Radio Select Metabox

There have been many times we have wanted to use taxonomies as a 1-to-1 ratio with a post or custom post types. This is arguably more effective than using metadata because as Alex King pointed out, using a taxonomy query is more efficient than using a meta query, not to mention all the other cool things that are done by default with custom taxonomies (i.e. admin columns).

This snippet replaces the default taxonomy checkbox select metabox for hierarchical taxonomies with a radio select metabox, which effectively limits your taxonomy selection to one term. Just include this file from your functions.php or plugin file and update the parameters at the bottom.

Note: A radio select metabox will get out of hand quickly if more than a few terms are needed.

Update:  Helen Housandi was kind enough to look over our snippet and provide some feedback. Thanks to that, there are some pretty awesome improvements to the class.

Update 2: Code is now on Github. Forks/pull requests welcome.

[snippet slug=taxonomy-radio-metabox]

View or fork on github.

Exit mobile version