Guest User

Untitled

a guest
Dec 18th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. /*****************************************META FOR TAXONOMIES**************************************************************/
  2.  
  3.  
  4. // Редактирование мета поля
  5.  
  6. function pippin_taxonomy_edit_meta_field($term) {
  7.  
  8. // put the term ID into a variable
  9. $t_id = $term->term_id;
  10.  
  11. // retrieve the existing value(s) for this meta field. This returns an array
  12. $term_meta = get_option( "taxonomy_$t_id" ); ?>
  13. <tr class="form-field">
  14. <th scope="row" valign="top"><label for="meta_title">МETA Title</label></th>
  15. <td>
  16. <input type="text" name="term_meta[title]" id="meta_title" value="<?php echo esc_attr( $term_meta['title'] ) ? esc_attr( $term_meta['title'] ) : ''; ?>">
  17. <p class="description"></p>
  18. </td>
  19. </tr>
  20.  
  21. <tr class="form-field">
  22. <th scope="row" valign="top"><label for="term_meta[custom_term_meta]">META description</label></th>
  23. <td>
  24. <textarea name="term_meta[description]" id="meta_description" rows="4"><?php echo esc_attr( $term_meta['description'] ) ? esc_attr( $term_meta['description'] ) : ''; ?></textarea>
  25. <p class="description"></p>
  26. </td>
  27. </tr>
  28.  
  29. <?php
  30. }
  31. add_action( 'category_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
  32. add_action( 'renter_type_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
  33. add_action( 'event_type_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
  34.  
  35. // Сохранение метаполя
  36.  
  37. function save_taxonomy_custom_meta( $term_id ) {
  38. if ( isset( $_POST['term_meta'] ) ) {
  39. $t_id = $term_id;
  40. $term_meta = get_option( "taxonomy_$t_id" );
  41. $cat_keys = array_keys( $_POST['term_meta'] );
  42. foreach ( $cat_keys as $key ) {
  43. if ( isset ( $_POST['term_meta'][$key] ) ) {
  44. $term_meta[$key] = $_POST['term_meta'][$key];
  45. }
  46. }
  47. // Save the option array.
  48. update_option( "taxonomy_$t_id", $term_meta );
  49. }
  50. }
  51. add_action( 'edited_category', 'save_taxonomy_custom_meta', 10, 2 );
  52.  
  53.  
  54.  
  55.  
  56.  
  57. // define the aioseop_title callback
  58. function filter_aioseop_title( $title ) {
  59. if (is_tax()) {
  60. $t_id = get_queried_object()->term_id;
  61. $term_meta = get_option( "taxonomy_$t_id" );
  62. $title = $term_meta['title']!="" ? $term_meta['title'] : $title;
  63. //$title = "123";
  64. }
  65. return $title;
  66. };
  67.  
  68. // add the filter
  69. add_filter( 'aioseop_title', 'filter_aioseop_title', 10, 1 );
  70.  
  71.  
  72. // define the aioseop_description callback
  73. function filter_aioseop_description( $description ) {
  74. if (is_tax()) {
  75. $t_id = get_queried_object()->term_id;
  76. $term_meta = get_option( "taxonomy_$t_id" );
  77. $description = $term_meta['description']!="" ? $term_meta['description'] : $description;
  78.  
  79. }
  80. return $description;
  81. };
  82.  
  83. // add the filter
  84. add_filter( 'aioseop_description', 'filter_aioseop_description', 10, 1 );
  85.  
  86.  
  87. /*****************************************end META FOR TAXONOMIES**************************************************************/
Add Comment
Please, Sign In to add comment