Advertisement
Guest User

Untitled

a guest
Oct 7th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. // Add term page
  2. function pippin_taxonomy_add_new_meta_field() {
  3. // this will add the custom meta field to the add new term page
  4. ?>
  5. <div class="form-field">
  6. <label for="term_meta[custom_term_meta]"><?php _e( 'Example meta field', 'pippin' ); ?></label>
  7. <input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="">
  8. <p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
  9. </div>
  10. <?php
  11. }
  12. add_action( 'personaje_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
  13.  
  14. // Edit term page
  15. function pippin_taxonomy_edit_meta_field($term) {
  16.  
  17. // put the term ID into a variable
  18. $t_id = $term->term_id;
  19.  
  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[custom_term_meta]"><?php _e( 'Example meta field', 'pippin' ); ?></label></th>
  24. <td>
  25. <input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="<?php echo esc_attr( $term_meta['custom_term_meta'] ) ? esc_attr( $term_meta['custom_term_meta'] ) : ''; ?>">
  26. <p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
  27. </td>
  28. </tr>
  29. <?php
  30. }
  31. add_action( 'personaje_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
  32.  
  33. // Save extra taxonomy fields callback function.
  34. function save_taxonomy_custom_meta( $term_id ) {
  35. if ( isset( $_POST['term_meta'] ) ) {
  36. $t_id = $term_id;
  37. $term_meta = get_option( "taxonomy_$t_id" );
  38. $cat_keys = array_keys( $_POST['term_meta'] );
  39. foreach ( $cat_keys as $key ) {
  40. if ( isset ( $_POST['term_meta'][$key] ) ) {
  41. $term_meta[$key] = $_POST['term_meta'][$key];
  42. }
  43. }
  44. // Save the option array.
  45. update_option( "taxonomy_$t_id", $term_meta );
  46. }
  47. }
  48. add_action( 'edited_category', 'save_taxonomy_custom_meta', 10, 2 );
  49. add_action( 'create_category', 'save_taxonomy_custom_meta', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement