Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Search Filter for property
- ================================= */
- if(!function_exists('imic_search_filter')){
- function imic_search_filter($query) {
- if($query->is_search()) {
- $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='';
- $property_contract_type = isset($_GET['property_contract_type'])?$_GET['property_contract_type']:"";
- $property_contract_type = ($property_contract_type == __('Contract', 'framework')) ? '' :$property_contract_type;
- $property_type = isset($_GET['property_type'])?$_GET['property_type']:'';
- $property_type = ($property_type == __('Any', 'framework')) ? '' :$property_type;
- $property_report = isset($_GET['hide-reports'])?$_GET['hide-reports']:'';
- $property_report = ($property_report == __('Any', 'framework')) ? '' :$property_report;
- $property_neighborhood = isset($_GET['neighborhood'])?$_GET['neighborhood']:'';
- $property_neighborhood = ($property_neighborhood == __('Neighborhood', 'framework')) ? '' :$property_neighborhood;
- $property_state_value = isset($_GET['property_state'])?$_GET['property_state']:'';
- $property_state_value = ($property_state_value == __('Any State', 'framework')) ? '' : $property_state_value;
- $property_city = isset($_GET['property_city'])?$_GET['property_city']:'';
- $property_city = ($property_city == __('Any City', 'framework')) ? '' :$property_city;
- $beds = isset($_GET['beds'])?$_GET['beds']:'';
- $beds = ($beds == __('Any', 'framework')) ? '' : $beds;
- $baths = isset($_GET['baths'])?$_GET['baths']:'';
- $baths = ($baths == __('Any', 'framework')) ? '' : $baths;
- $min_price = isset($_GET['min_price'])?$_GET['min_price']:'';
- $min_price = ($min_price == __('Any', 'framework')) ? '' :$min_price;
- $max_price = isset($_GET['max_price'])?$_GET['max_price']:'';
- $max_price = ($max_price == __('Any', 'framework')) ? '' :$max_price;
- $min_area = isset($_GET['min_area'])?$_GET['min_area']:'';
- $min_area = ($min_area == __('Any', 'framework')) ? '' :$min_area;
- $max_area = isset($_GET['max_area'])?$_GET['max_area']:'';
- $max_area = ($max_area == __('Any', 'framework')) ? '' :$max_area;
- // Agent Property Value and Ratings
- $value_rating = isset($_GET['vr'])?$_GET['vr']:'';
- $value_rating = ($value_rating == __('Any', 'framework')) ? '' :$value_rating;
- $apor = isset($_GET['rating_r'])?$_GET['rating_r']:'';
- $apor = ($apor == __('Any', 'framework')) ? '' :$apor;
- $id = isset($_GET['id'])?$_GET['id']:'';
- $pincode = isset($_GET['pincode'])?$_GET['pincode']:'';
- $address = isset($_GET['address'])?$_GET['address']:'';
- // If the default text is in the box
- 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)) {
- $s = $_GET['s'];
- foreach($_GET as $key => $value){
- if($key == 'property_type'){
- $item_property_type['taxonomy'] = htmlspecialchars($key);
- $item_property_type['terms'] = htmlspecialchars($value);
- $item_property_type['field'] = 'slug';
- $list[] = $item_property_type;
- }
- }
- $taxproperty_type = array_merge(array('relation' => 'OR'), $list);
- $meta_query=array();
- if ($s == __('Search', 'framework')) {
- $query->set('s', '');
- }
- $query->set('post_type', 'property');
- $query->set('post_status','publish');
- if (!empty($property_type)) {
- $query->set('tax_query',$taxproperty_type);
- }
- if (!empty($property_city)) {
- $query->set('city-type',$property_city);
- }
- if (!empty($property_neighborhood)) {
- $query->set('neighborhood',$property_neighborhood);
- }
- if (!empty($property_contract_type)) {
- $query->set('property-contract-type', $property_contract_type);
- }
- if (!empty($property_report)) {
- $query->set('hide-reports', $property_report);
- }
- if (!empty($baths)) {
- array_push($meta_query, array(
- 'key' => 'imic_property_baths',
- 'value' => $baths,
- 'type' => 'numeric',
- 'compare' => '>='
- ));
- }
- if (!empty($beds)) {
- array_push($meta_query,array(
- 'key' => 'imic_property_beds',
- 'value' => $beds,
- 'type' => 'numeric',
- 'compare' => '>='
- ));
- }
- if(!empty($min_price)&&!empty($max_price)){
- array_push($meta_query,array(
- 'key' =>'imic_property_price',
- 'value'=>array($min_price,$max_price),
- 'type' =>'numeric',
- 'compare'=> 'BETWEEN'
- ));
- }
- else{
- if(!empty($min_price)){
- array_push($meta_query,array(
- 'key' =>'imic_property_price',
- 'value'=>$min_price,
- 'type' =>'numeric',
- 'compare'=> '>='
- ));
- }
- if(!empty($max_price)){
- array_push($meta_query,array(
- 'key' =>'imic_property_price',
- 'value'=>$max_price,
- 'type' =>'numeric',
- 'compare'=> '<='
- ));
- }
- }if(!empty($min_area)&&!empty($max_area)){
- array_push($meta_query,array(
- 'key' => 'imic_property_area',
- 'value' => array($min_area,$max_area),
- 'type' => 'numeric',
- 'compare' => 'BETWEEN'
- ));
- }
- else{
- if(!empty($min_area)){
- array_push($meta_query,array(
- 'key' => 'imic_property_area',
- 'value' => $min_area,
- 'type' => 'numeric',
- 'compare' => '>='
- ));
- }
- if(!empty($max_area)){
- array_push($meta_query,array(
- 'key' => 'imic_property_area',
- 'value' => $max_area,
- 'type' => 'numeric',
- 'compare' => '<='
- ));
- }
- }
- if (!empty($property_state_value)) {
- array_push($meta_query,array(
- 'key' => 'property_state',
- 'value' => $property_state_value
- ));
- }
- if (!empty($value_rating)) {
- array_push($meta_query,array(
- 'key' => 'vr',
- 'value' => $value_rating
- ));
- }
- if (!empty($apor)) {
- array_push($meta_query,array(
- 'key' => 'rating_r',
- 'value' => $apor,
- ));
- }
- if (!empty($id)) {
- array_push($meta_query,array(
- 'key' => 'imic_property_site_id',
- 'value' => $id,
- 'compare'=>'LIKE'
- ));
- }
- if (!empty($pincode)) {
- array_push($meta_query,array(
- 'key' => 'imic_property_pincode',
- 'value' => $pincode
- ));
- }
- if (!empty($address)) {
- array_push($meta_query,array(
- 'key' => 'imic_property_site_address',
- 'value' => $address,
- 'compare' => 'LIKE',
- ));
- }
- $query->set('meta_query',$meta_query);
- }else {
- $s = $_GET['s'];
- if ($s == __('Search', 'framework')) {
- $query->set('s', '');
- $query->set('post_type', 'property');
- }else{
- $query->set('post_type', 'property');
- } }
- }
- return $query;
- }
- # Add Filters
- if(!is_admin()) {
- add_filter('pre_get_posts', 'imic_search_filter'); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement