The default behaviour of WordPress doesn't allow this.
So, to do this, I'd suggest the following method:
- Register the taxonomy as usual
- Remove the taxonomy meta box so users don't select the taxonomy term the old way
- Create your own meta box with your own UI to replace the taxonomy meta box. So users can only select a term from your radio list or select dropdown.
The 2nd step can be done with this code:
add_action( 'add_meta_boxes', function() {
remove_meta_box( $id, $post_type, $contex'side' );
} );
$id
is the ID of the taxonomy meta box, which can be either 'tagsdiv-{$tax-name}'
if the taxonomy is not hierarchical (like tags), or '{$tax-name}div'
if the taxonomy is hierarchical (like category).
The 3rd step can be done manually, but as it involves with outputting fields, handling sanitization, saving data, I'd suggest using a library like Meta Box plugin to do that. (Disclaimer: I'm the author of the plugin).
The code to do for meta box looks like this:
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'custom-meta-box',
'name' => 'Taxonomy Name',
'context' => 'side',
'fields' => array(
array(
'id' => 'custom_taxonomy',
'name' => 'Taxonomy Name',
'taxonomy' => $taxonomy_slug,
'type' => 'taxonomy',
),
),
);
return $meta_boxes;
} );
More docs can be found here.