Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. <?php
  2. function property_search_form($search_layout, $widget=false) {
  3.  
  4. // Prepare form attribute
  5. $search_pages = get_pages(array(
  6. 'meta_key' => '_wp_page_template',
  7. 'meta_value' => 'template-property-search.php'
  8. ));
  9. if($search_pages) {
  10. $search_pages = array_values($search_pages);
  11. $search_page_id = $search_pages[0]->ID;
  12. $target_url = get_permalink($search_page_id);
  13. } else {
  14. $target_url = get_home_url();
  15. }
  16.  
  17. // Prepare All metas
  18. $all_properties = get_posts(array('post_type'=>'property', 'posts_per_page'=>-1, 'bypass_filter'=>true,'suppress_filters'=>0, 'fields' => 'ids'));
  19. $meta_beds = $meta_baths = $meta_price = $meta_area = array();
  20. foreach ($all_properties as $property) {
  21. $meta_beds[] = get_post_meta( $property, '_meta_bedroom', true );
  22. $meta_bathroom[] = get_post_meta( $property, '_meta_bathroom', true );
  23. $meta_price[] = get_post_meta( $property, '_meta_price', true );
  24. $meta_area[] = get_post_meta( $property, '_meta_area', true );
  25. }
  26.  
  27. $meta_price = array_filter($meta_price, 'lt_filter_blank');
  28. $meta_area = array_filter($meta_area, 'lt_filter_blank');
  29. ?>
  30.  
  31. <form method="get" action="<?php echo esc_url($target_url); ?>" class="property-search-form">
  32.  
  33. <?php if(isset($_REQUEST['lang'])): ?>
  34. <input type="hidden" name="lang" value="<?php echo esc_attr($_REQUEST['lang']); ?>" />
  35. <?php endif; ?>
  36.  
  37. <?php if(!isset($search_page_id)): ?>
  38. <input type="hidden" name="post_type" value="<?php echo esc_attr(nt_get_option('property', 'slug', 'property')); ?>" />
  39. <?php endif; ?>
  40.  
  41. <input type="hidden" name="property-search" value="true" />
  42. <div class="row">
  43.  
  44. <?php if($search_layout != 'compact' && !$widget): ?>
  45. <div class="columns large-2 medium-4 search-id">
  46. <label><?php _e('Property ID', 'theme_front'); ?></label>
  47. <input type="text" name="property-id" placeholder="<?php _e('Any', 'theme_front'); ?>" value="<?php echo esc_attr(nt_get_request('property-id')); ?>" tabindex="1" />
  48. </div>
  49. <?php endif; ?>
  50.  
  51. <div class="columns large-4 medium-4 search-location">
  52. <label><?php _e('Property Location', 'theme_front'); ?></label>
  53. <select class="select2" name="s-location" tabindex="2">
  54. <option value=""><?php _e('Any', 'theme_front'); ?></option>
  55. <?php
  56. $terms = get_terms( 'location', array('orderby' => 'name', 'hide_empty' => 1));
  57. $terms_sorted = array();
  58. nt_sort_terms_hierarchicaly($terms, $terms_sorted);
  59. foreach($terms_sorted as $term):
  60. ?>
  61. <option value="<?php echo esc_attr($term->term_id); ?>" <?php if(nt_get_request('s-location') == $term->term_id) echo 'selected="selected"'; ?>><?php echo esc_html($term->name); ?></option>
  62. <?php foreach($term->children as $term_child): ?>
  63. <option value="<?php echo esc_attr($term_child->term_id); ?>" <?php if(nt_get_request('s-location') == $term_child->term_id) echo 'selected="selected"'; ?>>- <?php echo esc_html($term_child->name); ?></option>
  64. <?php foreach($term_child->children as $term_3child): ?>
  65. <option value="<?php echo esc_attr($term_3child->term_id); ?>" <?php if(nt_get_request('s-location') == $term_3child->term_id) echo 'selected="selected"'; ?>>-- <?php echo esc_html($term_3child->name); ?></option>
  66. <?php endforeach; ?>
  67. <?php endforeach; ?>
  68. <?php endforeach; ?>
  69. </select>
  70. </div>
  71. <div class="columns large-3 medium-4 small-6 search-status">
  72. <label><?php _e('Property Status', 'theme_front'); ?></label>
  73. <select class="select2" name="s-status" tabindex="3">
  74. <option value=""><?php _e('Any', 'theme_front'); ?></option>
  75. <?php
  76. $terms = get_terms( 'status', array('orderby' => 'name', 'hide_empty' => 1));
  77. $terms_sorted = array();
  78. nt_sort_terms_hierarchicaly($terms, $terms_sorted);
  79. foreach($terms_sorted as $term):
  80. ?>
  81. <option value="<?php echo esc_attr($term->term_id); ?>" <?php if(nt_get_request('s-status') == $term->term_id) echo 'selected="selected"'; ?>><?php echo esc_html($term->name); ?></option>
  82. <?php foreach($term->children as $term_child): ?>
  83. <option value="<?php echo esc_attr($term_child->term_id); ?>" <?php if(nt_get_request('s-status') == $term_child->term_id) echo 'selected="selected"'; ?>>- <?php echo esc_html($term_child->name); ?></option>
  84. <?php endforeach; ?>
  85. <?php endforeach; ?>
  86. </select>
  87. </div>
  88. <div class="columns large-3 medium-4 small-6 search-type">
  89. <label><?php _e('Property Type', 'theme_front'); ?></label>
  90. <select class="select2" name="s-type" tabindex="4">
  91. <option value=""><?php _e('Any', 'theme_front'); ?></option>
  92. <?php
  93. $terms = get_terms( 'type', array('orderby' => 'name', 'hide_empty' => 1));
  94. $terms_sorted = array();
  95. nt_sort_terms_hierarchicaly($terms, $terms_sorted);
  96. foreach($terms_sorted as $term):
  97. ?>
  98. <option value="<?php echo esc_attr($term->term_id); ?>" <?php if(nt_get_request('s-type') == $term->term_id) echo 'selected="selected"'; ?>><?php echo esc_html($term->name); ?></option>
  99. <?php foreach($term->children as $term_child): ?>
  100. <option value="<?php echo esc_attr($term_child->term_id); ?>" <?php if(nt_get_request('s-type') == $term_child->term_id) echo 'selected="selected"'; ?>>- <?php echo esc_html($term_child->name); ?></option>
  101. <?php endforeach; ?>
  102. <?php endforeach; ?>
  103. </select>
  104. </div>
  105.  
  106. <?php if($search_layout != 'compact' && !$widget): ?>
  107. <div class="vspace show-for-large-up"></div>
  108. <?php endif; ?>
  109.  
  110. <?php if($search_layout != 'compact' && !$widget): ?>
  111. <div class="columns large-2 medium-4 small-6 search-bed">
  112. <label><?php _e('Min Beds', 'theme_front'); ?></label>
  113. <select class="select2" name="min-bed" data-minimum-results-for-search="Infinity" tabindex="5">
  114. <option value=""><?php _e('Any', 'theme_front'); ?></option>
  115. <?php
  116. $meta = $meta_beds;
  117. $max = floor(max($meta));
  118. for($i=1; $i<=$max; $i++):
  119. ?>
  120. <option value="<?php echo esc_attr($i); ?>" <?php if(nt_get_request('min-bed') == $i) echo 'selected="selected"'; ?>><?php echo esc_html($i); ?></option>
  121. <?php endfor; ?>
  122. </select>
  123. </div>
  124. <?php endif; ?>
  125.  
  126. <?php if($search_layout != 'compact' && !$widget): ?>
  127. <div class="columns large-2 medium-4 small-6 search-bath">
  128. <label><?php _e('Min Baths', 'theme_front'); ?></label>
  129. <select class="select2" name="min-bath" data-minimum-results-for-search="Infinity" tabindex="6">
  130. <option value=""><?php _e('Any', 'theme_front'); ?></option>
  131. <?php
  132. $meta = $meta_bathroom;
  133. $max = floor(max($meta));
  134. for($i=1; $i<=$max; $i++):
  135. ?>
  136. <option value="<?php echo esc_attr($i); ?>" <?php if(nt_get_request('min-bath') == $i) echo 'selected="selected"'; ?>><?php echo esc_html($i); ?></option>
  137. <?php endfor; ?>
  138. </select>
  139. </div>
  140. <?php endif; ?>
  141.  
  142. <?php if($search_layout != 'compact' && $meta_price): ?>
  143. <div class="columns large-3 medium-6 search-price">
  144. <?php
  145. $meta = $meta_price;
  146.  
  147. // Remove non numeric value
  148. foreach($meta as $key => $m) {
  149. if(!is_numeric($m)) unset($meta[$key]);
  150. }
  151.  
  152. $max = ceil(max($meta));
  153. $min = 0;
  154. $exp = strlen($max-$min)-2;
  155. if($exp < 0) $exp = 0;
  156. $step = pow(10, $exp);
  157. $step = 10;
  158. $cur_min = nt_get_request('l-price');
  159. $cur_max = nt_get_request('u-price');
  160. if(!$cur_min) $cur_min = $min;
  161. if(!$cur_max) $cur_max = $max;
  162. ?>
  163. <label><?php _e('Price', 'theme_front'); ?> <small class="right"><span class="lower"><?php echo nt_currency($cur_min); ?></span> - <span class="upper"><?php echo nt_currency($cur_max); ?></span></small></label>
  164. <div class="rangeSlider" data-min="<?php echo esc_attr($min); ?>" data-max="<?php echo esc_attr($max); ?>" data-cmin="<?php echo esc_attr($cur_min); ?>" data-cmax="<?php echo esc_attr($cur_max); ?>" data-step="<?php echo esc_attr($step); ?>" data-margin="<?php echo esc_attr($step); ?>" data-decimal-point="<?php echo nt_get_option('property', 'decimal_point', '.'); ?>" data-thousands-sep="<?php echo nt_get_option('property', 'thousands_sep', ','); ?>" data-direction="<?php echo nt_text_direction(); ?>"></div>
  165. <input type="hidden" name="l-price" class="lower" />
  166. <input type="hidden" name="u-price" class="upper" />
  167. </div>
  168. <?php endif; ?>
  169.  
  170. <?php if($search_layout != 'compact' && $meta_area): ?>
  171. <div class="columns large-3 medium-6 search-area">
  172. <?php
  173. $meta = $meta_area;
  174.  
  175. // Remove non numeric value
  176. foreach($meta as $key => $m) {
  177. if(!is_numeric($m)) unset($meta[$key]);
  178. }
  179.  
  180. $max = ceil(max($meta));
  181. $min = 0;
  182. $exp = strlen($max-$min)-2;
  183. if($exp < 0) $exp = 0;
  184. $step = pow(10, $exp);
  185. $step = 10;
  186. $cur_min = nt_get_request('l-area');
  187. $cur_max = nt_get_request('u-area');
  188. if(!$cur_min) $cur_min = $min;
  189. if(!$cur_max) $cur_max = $max;
  190. ?>
  191. <label><?php _e('Area', 'theme_front'); ?> <small class="right"><span class="lower"><span></span> <?php echo nt_get_option('property', 'area'); ?></span> - <span class="upper"><span></span> <?php echo nt_get_option('property', 'area'); ?></span> </small></label>
  192. <div class="rangeSlider" data-min="<?php echo esc_attr($min); ?>" data-max="<?php echo esc_attr($max); ?>" data-cmin="<?php echo esc_attr($cur_min); ?>" data-cmax="<?php echo esc_attr($cur_max); ?>" data-step="<?php echo esc_attr($step); ?>" data-margin="<?php echo esc_attr($step); ?>" data-decimal-point="<?php echo nt_get_option('property', 'decimal_point', '.'); ?>" data-thousands-sep="<?php echo nt_get_option('property', 'thousands_sep', ','); ?>" data-direction="<?php echo nt_text_direction(); ?>"></div>
  193. <input type="hidden" name="l-area" class="lower" />
  194. <input type="hidden" name="u-area" class="upper" />
  195. </div>
  196. <?php endif; ?>
  197.  
  198. <div class="columns large-2 search-submit">
  199. <label class="hidden"><?php _e('SEARCH', 'theme_front'); ?></label>
  200. <input type="submit" value="<?php _e('SEARCH', 'theme_front'); ?>" class="lt-button primary" />
  201. </div>
  202. </div>
  203. </form>
  204.  
  205. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement