Guest User

Untitled

a guest
Dec 11th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. // Add term page
  2. function summit_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[displayed]"><?php _e( 'Display Category', 'summit' ); ?></label>
  7. <input type="hidden" name="term_meta[helpme]" value="z">
  8. <input type="checkbox" name="term_meta[displayed]" id="term_meta[displayed]" value="1">
  9. <p class="description"><?php _e( 'Check to have the Category to displayed on the Sales Page','summit' ); ?></p>
  10. </div>
  11. <?php
  12. }
  13. add_action( 'category_add_form_fields', 'summit_taxonomy_add_new_meta_field', 10, 2 );
  14.  
  15. // Edit term page
  16. function summit_taxonomy_edit_meta_field($term) {
  17.  
  18. // put the term ID into a variable
  19. $t_id = $term->term_id;
  20.  
  21. // retrieve the existing value(s) for this meta field. This returns an array
  22. $term_meta = get_option( "taxonomy_$t_id" ); ?>
  23. <tr class="form-field">
  24. <th scope="row" valign="top"><label for="term_meta[displayed]"><?php _e( 'Display Category', 'summit' ); ?></label></th>
  25. <td>
  26. <input type="hidden" name="term_meta[helpme]" value="z">
  27. <input type="checkbox" name="term_meta[displayed]" id="term_meta[displayed]" value="1" <?php if( isset( $term_meta['displayed'] ) ) { ?>checked="checked"<?php } ?> ">
  28. <p class="description"><?php _e( 'Check to have the Category to displayed on the Sales Page','summit' ); ?></p>
  29. </td>
  30. </tr>
  31. <?php
  32. }
  33. add_action( 'category_edit_form_fields', 'summit_taxonomy_edit_meta_field', 10, 2 );
  34.  
  35. // Save extra taxonomy fields callback function.
  36. function save_taxonomy_custom_meta( $term_id ) {
  37. $new_meta = array();
  38. if ( isset( $_POST['term_meta'] ) ) {
  39. $t_id = $term_id;
  40. $cat_keys = array_keys( $_POST['term_meta'] );
  41. foreach ( $cat_keys as $key ) {
  42. if ( isset ( $_POST['term_meta'][$key] ) ) {
  43. $new_meta[$key] = $_POST['term_meta'][$key];
  44. }
  45. }
  46. }
  47. // Save the option array.
  48. update_option( "taxonomy_$t_id", $new_meta );
  49. }
  50. add_action( 'edited_category', 'save_taxonomy_custom_meta', 10, 2 );
  51. add_action( 'create_category', 'save_taxonomy_custom_meta', 10, 2 );
Add Comment
Please, Sign In to add comment