Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tomdevisser/5bba174d5fae0f558eb357083dca7a94 to your computer and use it in GitHub Desktop.
Save tomdevisser/5bba174d5fae0f558eb357083dca7a94 to your computer and use it in GitHub Desktop.
Requires the custom walker class found in class-walker-taxonomy-radio-list.php.
<?php
/**
* Displays a custom taxonomy meta box with radio inputs.
*
* @param WP_Post $post Current post object.
* @param array $box Categories meta box arguments.
* @return void
*/
function toms_custom_meta_box_with_radio_inputs( WP_Post $post, array $box ): void {
$tax_name = esc_attr( $box['args']['taxonomy'] );
?>
<div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv toms-custom-meta-box">
<?php echo "<input type='hidden' name='tax_input[' . $tax_name . ']' value='0' />"; ?>
<ul id="<?php echo $tax_name; ?>radiolist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
<?php
wp_terms_checklist(
$post->ID,
array(
'taxonomy' => $tax_name,
'walker' => new Walker_Taxonomy_Radio_List(),
)
);
?>
</ul>
</div>
<?php
}
@tomdevisser
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment