Last active
February 9, 2025 22:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires the custom walker class found in https://gist.github.com/tomdevisser29/cd6f43f6111c3f1ec9aa4b3c319e0f17.