Sacconi69

tags

May 9th, 2024
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. //mostra i checkbox dei tag
  2.  
  3. $mytags = get_tags
  4.  
  5. ( array(
  6. 'taxonomy' => 'post_tag',
  7. 'hide_empty' => false, // Include empty terms as well
  8. 'exclude' => '442, 255, 326, 421,441', // term IDs to exclude
  9. ));
  10.  
  11. global $post;
  12. $lang = substr( get_locale(), 0, 2);
  13. $locale = get_locale();
  14. $tags = "<span class=\"checkmark\"></span>";
  15.  
  16. foreach ($mytags as $term){
  17.  
  18. $checked = empty( get_query_var('tag__and')) ? '': checked( in_array( $term->term_id, get_query_var('tag__and')), true, false );
  19.  
  20. //prova checked wi-fi
  21. if ( 203 == $term->term_id ) {
  22. empty( get_query_var('tag__in')) ? '': checked( in_array( $term->term_id, get_query_var('tag__in')), true, false );
  23. }
  24. //fine prova
  25.  
  26. if ('it_IT' != $locale ) {
  27.  
  28. $termine_straniero = get_term_meta($term->term_id, 'function_post_tag_'.$lang , true );
  29.  
  30. $tags .= "<input type=\"checkbox\" $checked name=\"tag__and[]\" value=\"{$term->term_id}\">";
  31.  
  32. $tags .= "<label class=\"testotag\">$termine_straniero</label><br>";
  33. $tags .= "<span class=\"checkmark\"></span>";
  34.  
  35.  
  36. } else {
  37. $tags .= "<input type=\"checkbox\" $checked name=\"tag__and[]\" value=\"{$term->term_id}\">";
  38.  
  39. $tags .= "<label class=\"testotag\">{$term->name} </label><br>";
  40. $tags .= "<span class=\"checkmark\"></span>";
  41.  
  42. }
  43. }
  44.  
  45.  
  46.  
  47. // Form output
  48. $output = '<form class="sacconi_form" method="get" action="' . home_url('/') . '">' .
  49. $categories . $tipologia . $functionOspitiDropdown . $functionCamereDropdown . $functionBagniDropdown . $functionNumberDropdown .
  50. '<input type="submit" name="search" value="' . esc_html__('Search', 'sacconicase') . '">' . '<br><br>' . $tags . '<input type="submit" name="search" value="' . esc_html__('Search', 'sacconicase') . '">' .
  51. '</form>';
  52.  
  53. return $output;
  54. }
  55.  
  56. //filters
  57.  
  58. add_action( 'pre_get_posts', 'bedrooms_guests_search_query');
  59.  
  60. function bedrooms_guests_search_query( $query ) {
  61. if (! is_admin() && $query->is_main_query()) {
  62.  
  63. //nuovo test per tag
  64. if ( array_key_exists('tag__and', $_GET ) && in_array( 203, $_GET['tag__and'])) {
  65. $query->set('tag__and', array_diff( $_GET['tag__and'], array(203,)));
  66.  
  67. $query->set('tag__in', array(203,421,198,441));
  68.  
  69. }
  70. //fine test
  71.  
  72. //nuovo test per tag2
  73. if ( array_key_exists('tag__and', $_GET ) && in_array( 198, $_GET['tag__and'])) {
  74. $query->set('tag__and', array_diff( $_GET['tag__and'], array(198,)));
  75.  
  76. $query->set('tag__in', array(198,441,203,421));
  77.  
  78. }
  79. //fine test
  80.  
  81.  
  82. if ( array_key_exists('function_camere', $_GET ) &&
  83.  
  84. array_key_exists('function_ospiti', $_GET ) && array_key_exists('function_bagni', $_GET )&& array_key_exists('function_number', $_GET )) {
  85.  
  86. $meta_query = array(
  87. array(
  88. 'key' => 'function_ospiti',
  89. 'value' => (int) $_GET['function_ospiti'],
  90. 'type' => 'numeric',
  91. 'compare' => '>=',
  92. ),
  93. array(
  94. 'key' => 'function_camere',
  95. 'value' => (int) $_GET['function_camere'],
  96. 'type' => 'numeric',
  97. 'compare' => '>=',
  98. ),
  99.  
  100. array(
  101. 'key' => 'function_bagni',
  102. 'value' => (int) $_GET['function_bagni'],
  103. 'type' => 'numeric',
  104. 'compare' => '>=',
  105. ),
  106. array(
  107. 'key' => 'function_number',
  108. 'value' => $_GET['function_number'] == 0 ? 9999 : $_GET['function_number'],
  109. 'type' => 'numeric',
  110. 'compare' => '<=',
  111.  
  112.  
  113. ),
  114.  
  115.  
  116. );
  117.  
  118. $query->set("meta_query", $meta_query);
  119.  
  120. }
  121. }
  122. }
  123.  
  124.  
  125.  
  126.  
Advertisement
Add Comment
Please, Sign In to add comment