Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. function places_taxonomy_add_new_meta_fields() {
  2. ?>
  3. <div class="form-field">
  4.   <label for="term_meta[place_url_title]"><?php _e('Place URL Title',''); ?></label>  
  5.   <input type="text" name="term_meta[place_url_title]" id="term_meta[place_url_title]" size="40" value="">  
  6.   <p><?php _e('Place URL Title'); ?></p>  
  7. </div>
  8. <div class="form-field term-url-wrap">
  9.   <label for="term_meta[place_url]"><?php _e('Place URL',''); ?></label>  
  10.   <input type="url" name="term_meta[place_url]" id="term_meta[place_url]" size="40" value="">  
  11.   <p><?php _e('Oficial Website'); ?></p>  
  12. </div>
  13. <?php  
  14. }
  15.  
  16. // Edit term page
  17. function places_taxonomy_edit_meta_fields($term) {
  18.     // put the term ID into a variable
  19.     $t_id = $term->term_id;
  20.   // retrieve the existing value(s) for this meta field. This returns an array
  21.     $term_meta = get_option( "taxonomy_$t_id" ); ?>
  22.     <tr class="form-field">
  23.     <th scope="row" valign="top"><label for="term_meta[place_title]"><?php _e( 'Place Title','' ); ?></label></th>
  24.         <td>
  25.             <input type="text" name="term_meta[place_title]" id="term_meta[place_title]" value="<?php echo esc_attr( $term_meta['place_title'] ) ? esc_attr( $term_meta['place_title'] ) : ''; ?>">
  26.             <p class="description"><?php _e( 'Enter a Oficial Website Title','' ); ?></p>
  27.         </td>
  28.     </tr>
  29.   <tr class="form-field">
  30.     <th scope="row" valign="top"><label for="term_meta[place_url]"><?php _e( 'Place URL','' ); ?></label></th>
  31.         <td>
  32.             <input type="url" name="term_meta[place_url]" id="term_meta[place_url]" value="<?php echo esc_attr( $term_meta['place_url'] ) ? esc_attr( $term_meta['place_url'] ) : ''; ?>">
  33.             <p class="description"><?php _e( 'Enter a Oficial Website','' ); ?></p>
  34.         </td>
  35.     </tr>
  36. <?php
  37. }
  38.  
  39. // Save extra taxonomy fields callback function.
  40. function save_taxonomy_custom_meta( $term_id ) {
  41.     if ( isset( $_POST['term_meta'] ) ) {
  42.         $t_id = $term_id;
  43.         $term_meta = get_option( "taxonomy_$t_id" );
  44.         $cat_keys = array_keys( $_POST['term_meta'] );
  45.         foreach ( $cat_keys as $key ) {
  46.             if ( isset ( $_POST['term_meta'][$key] ) ) {
  47.                 $term_meta[$key] = $_POST['term_meta'][$key];
  48.             }
  49.         }
  50.         // Save the option array.
  51.         update_option( "taxonomy_$t_id", $term_meta );
  52.     }
  53. }  
  54. add_action( 'places_taxonomy_add_form_fields', 'places_taxonomy_add_new_meta_fields', 10, 2 );
  55. add_action( 'places_taxonomy_edit_form_fields', 'places_taxonomy_edit_meta_fields', 10, 2 );
  56. add_action( 'edited_places_taxonomy', 'save_taxonomy_custom_meta', 10, 2 );
  57. add_action( 'create_places_taxonomy', 'save_taxonomy_custom_meta', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement