Advertisement
Guest User

Search Function

a guest
Dec 21st, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. /* Search Filter for property
  2. ================================= */
  3. if(!function_exists('imic_search_filter')){
  4. function imic_search_filter($query) {
  5. if($query->is_search()) {
  6. $property_contract_type=$property_report=$property_type=$property_neighborhood=$property_state_value=$property_city=$beds=$baths=$min_price=$max_price=$min_area=$max_area=$value_rating=$apor='';
  7. $property_contract_type = isset($_GET['property_contract_type'])?$_GET['property_contract_type']:"";
  8. $property_contract_type = ($property_contract_type == __('Contract', 'framework')) ? '' :$property_contract_type;
  9. $property_type = isset($_GET['property_type'])?$_GET['property_type']:'';
  10. $property_type = ($property_type == __('Any', 'framework')) ? '' :$property_type;
  11. $property_report = isset($_GET['hide-reports'])?$_GET['hide-reports']:'';
  12. $property_report = ($property_report == __('Any', 'framework')) ? '' :$property_report;
  13. $property_neighborhood = isset($_GET['neighborhood'])?$_GET['neighborhood']:'';
  14. $property_neighborhood = ($property_neighborhood == __('Neighborhood', 'framework')) ? '' :$property_neighborhood;
  15. $property_state_value = isset($_GET['property_state'])?$_GET['property_state']:'';
  16. $property_state_value = ($property_state_value == __('Any', 'framework')) ? '' : $property_state_value;
  17. $property_city = isset($_GET['property_city'])?$_GET['property_city']:'';
  18. $property_city = ($property_city == __('City', 'framework')) ? '' :$property_city;
  19. $beds = isset($_GET['beds'])?$_GET['beds']:'';
  20. $beds = ($beds == __('Any', 'framework')) ? '' : $beds;
  21. $baths = isset($_GET['baths'])?$_GET['baths']:'';
  22. $baths = ($baths == __('Any', 'framework')) ? '' : $baths;
  23. $min_price = isset($_GET['min_price'])?$_GET['min_price']:'';
  24. $min_price = ($min_price == __('Any', 'framework')) ? '' :$min_price;
  25. $max_price = isset($_GET['max_price'])?$_GET['max_price']:'';
  26. $max_price = ($max_price == __('Any', 'framework')) ? '' :$max_price;
  27. $min_area = isset($_GET['min_area'])?$_GET['min_area']:'';
  28. $min_area = ($min_area == __('Any', 'framework')) ? '' :$min_area;
  29. $max_area = isset($_GET['max_area'])?$_GET['max_area']:'';
  30. $max_area = ($max_area == __('Any', 'framework')) ? '' :$max_area;
  31. // Agent Property Value and Ratings
  32. $value_rating = isset($_GET['vr'])?$_GET['vr']:'';
  33. $value_rating = ($value_rating == __('Any', 'framework')) ? '' :$value_rating;
  34. $apor = isset($_GET['rating_r'])?$_GET['rating_r']:'';
  35. $apor = ($apor == __('Any', 'framework')) ? '' :$apor;
  36. $id = isset($_GET['id'])?$_GET['id']:'';
  37. $pincode = isset($_GET['pincode'])?$_GET['pincode']:'';
  38. $address = isset($_GET['address'])?$_GET['address']:'';
  39. // If the default text is in the box
  40. if (!empty($property_contract_type)||!empty($property_report)||!empty($property_type)|| !empty($property_state_value) || !empty($baths) ||!empty($beds)||(!empty($min_price)||!empty($max_price))||(!empty($min_area)||!empty($max_area))||!empty($value_rating)||!empty($apor)||!empty($id)||!empty($pincode)||!empty($address)||!empty($property_city)||!empty($property_neighborhood)) {
  41. $s = $_GET['s'];
  42. $meta_query=array();
  43. if ($s == __('Search', 'framework')) {
  44. $query->set('s', '');
  45. }
  46. $query->set('post_type', 'property');
  47. $query->set('post_status','publish');
  48. if (!empty($property_type)) {
  49. $query->set('property-type', $property_type);
  50. }
  51. if (!empty($property_city)) {
  52. $query->set('city-type',$property_city);
  53. }
  54. if (!empty($property_neighborhood)) {
  55. $query->set('neighborhood',$property_neighborhood);
  56. }
  57. if (!empty($property_contract_type)) {
  58. $query->set('property-contract-type', $property_contract_type);
  59. }
  60.  
  61. if (!empty($property_report)) {
  62. $query->set('hide-reports', $property_report);
  63. }
  64.  
  65. if (!empty($baths)) {
  66. array_push($meta_query, array(
  67. 'key' => 'imic_property_baths',
  68. 'value' => $baths,
  69. 'type' => 'numeric',
  70. 'compare' => '>='
  71. ));
  72. }
  73. if (!empty($beds)) {
  74. array_push($meta_query,array(
  75. 'key' => 'imic_property_beds',
  76. 'value' => $beds,
  77. 'type' => 'numeric',
  78. 'compare' => '>='
  79. ));
  80. }
  81. if(!empty($min_price)&&!empty($max_price)){
  82. array_push($meta_query,array(
  83. 'key' =>'imic_property_price',
  84. 'value'=>array($min_price,$max_price),
  85. 'type' =>'numeric',
  86. 'compare'=> 'BETWEEN'
  87. ));
  88. }
  89. else{
  90. if(!empty($min_price)){
  91. array_push($meta_query,array(
  92. 'key' =>'imic_property_price',
  93. 'value'=>$min_price,
  94. 'type' =>'numeric',
  95. 'compare'=> '>='
  96. ));
  97. }
  98. if(!empty($max_price)){
  99. array_push($meta_query,array(
  100. 'key' =>'imic_property_price',
  101. 'value'=>$max_price,
  102. 'type' =>'numeric',
  103. 'compare'=> '<='
  104. ));
  105. }
  106. }if(!empty($min_area)&&!empty($max_area)){
  107. array_push($meta_query,array(
  108. 'key' => 'imic_property_area',
  109. 'value' => array($min_area,$max_area),
  110. 'type' => 'numeric',
  111. 'compare' => 'BETWEEN'
  112. ));
  113. }
  114. else{
  115. if(!empty($min_area)){
  116. array_push($meta_query,array(
  117. 'key' => 'imic_property_area',
  118. 'value' => $min_area,
  119. 'type' => 'numeric',
  120. 'compare' => '>='
  121. ));
  122. }
  123. if(!empty($max_area)){
  124. array_push($meta_query,array(
  125. 'key' => 'imic_property_area',
  126. 'value' => $max_area,
  127. 'type' => 'numeric',
  128. 'compare' => '<='
  129. ));
  130. }
  131. }
  132. if (!empty($property_state_value)) {
  133. array_push($meta_query,array(
  134. 'key' => 'property_state',
  135. 'value' => $property_state_value
  136. ));
  137. }
  138. if (!empty($value_rating)) {
  139. array_push($meta_query,array(
  140. 'key' => 'vr',
  141. 'value' => $value_rating
  142. ));
  143. }
  144. if (!empty($apor)) {
  145. array_push($meta_query,array(
  146. 'key' => 'rating_r',
  147. 'value' => $apor,
  148. ));
  149. }
  150. if (!empty($id)) {
  151. array_push($meta_query,array(
  152. 'key' => 'imic_property_site_id',
  153. 'value' => $id,
  154. 'compare'=>'LIKE'
  155. ));
  156. }
  157. if (!empty($pincode)) {
  158. array_push($meta_query,array(
  159. 'key' => 'imic_property_pincode',
  160. 'value' => $pincode
  161. ));
  162. }
  163. if (!empty($address)) {
  164. array_push($meta_query,array(
  165. 'key' => 'imic_property_site_address',
  166. 'value' => $address,
  167. 'compare' => 'LIKE',
  168. ));
  169. }
  170.  
  171. $query->set('meta_query',$meta_query);
  172. }else {
  173. $s = $_GET['s'];
  174. if ($s == __('Search', 'framework')) {
  175. $query->set('s', '');
  176. $query->set('post_type', 'property');
  177. }else{
  178. $query->set('post_type', 'property');
  179. } }
  180.  
  181. }
  182. return $query;
  183. }
  184. # Add Filters
  185. if(!is_admin()) {
  186. add_filter('pre_get_posts', 'imic_search_filter'); }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement