Guest User

Untitled

a guest
Sep 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. // Replace hierarchial taxonomy entry with radio field
  2. class exmp_tax_radio_field {
  3.     function add_theme_box() {
  4.         add_meta_box('theme_box_ID', __('Theme'), 'your_styling_function', 'post', 'side', 'core');
  5.     }  
  6.     function add_theme_menus() {
  7.         if ( ! is_admin() )
  8.             return;
  9.         add_action('admin_menu', 'add_theme_box');
  10.     }
  11.     add_theme_menus();
  12.     // This function gets called in edit-form-advanced.php
  13.     function your_styling_function($post) {
  14.         echo '<input type="hidden" name="taxonomy_noncename" id="taxonomy_noncename" value="' .
  15.                 wp_create_nonce( 'taxonomy_theme' ) . '" />';
  16.         // Get all theme taxonomy terms
  17.         $themes = get_terms('theme', 'hide_empty=0');
  18.     ?>
  19.     <select name='post_theme' id='post_theme'>
  20.         <!-- Display themes as options -->
  21.         <?php
  22.             $names = wp_get_object_terms($post->ID, 'journal_issue');
  23.             ?>
  24.             <option class='theme-option' value=''
  25.             <?php if (!count($names)) echo "selected";?>>None</option>
  26.             <?php
  27.         foreach ($themes as $theme) {
  28.             if (!is_wp_error($names) && !empty($names) && !strcmp($theme->slug, $names[0]->slug))
  29.                 echo "<option class='theme-option' value='" . $theme->slug . "' selected>" . $theme->name . "</option>\n";
  30.             else
  31.                 echo "<option class='theme-option' value='" . $theme->slug . "'>" . $theme->name . "</option>\n";
  32.         }
  33.        ?>
  34.     </select>    
  35.     <?php
  36.     }
  37. }
  38. $exmp_tax_radio_field = new exmp_tax_radio_field();
Add Comment
Please, Sign In to add comment