Example #1
0
                        echo __($search_labels[$i], 'tt');
                        ?>
 <span class="price-range-min"></span> <?php 
                        _e('to', 'tt');
                        ?>
 <span class="price-range-max"></span></label>
								<div class="price-range-slider"></div>
							</div>
							<?php 
                        break;
                }
            } else {
                if (tt_acf_active()) {
                    // Get ACF Field Type
                    $acf_field_position = array_search($search_field, tt_acf_fields_name(tt_acf_group_id_property()));
                    $acf_field_type_key = tt_acf_fields_type(tt_acf_group_id_property());
                    $acf_field_type = $acf_field_type_key[$acf_field_position];
                    // Single value based ACF fields, that appear next to default fields. Arrays such as checkboxes & radio buttons are shown under "more".
                    // $acf_supported_field_types = array( 'text', 'number', 'email', 'date_picker', 'select' );
                    //if ( in_array( $acf_field_type, $acf_supported_field_types ) ) {
                    echo '<div class="' . $columns . ' form-group">';
                    //}
                    // Field Type: Select, Checkbox
                    if ($acf_field_type == 'select' || $acf_field_type == 'checkbox' || $acf_field_type == 'radio') {
                        $acf_custom_keys = get_post_custom_keys(tt_acf_group_id_property());
                        $acf_object = get_field_object($search_field);
                        // ACF: Loop through field keys, as we can't output choices by name, but only by their key
                        foreach ($acf_custom_keys as $key => $value) {
                            if (stristr($value, 'field_')) {
                                $acf_field = get_field_object($value, tt_acf_group_id_property());
                                if ($acf_field['name'] == $search_field) {
function tt_property_search_args($search_results_args)
{
    global $realty_theme_option;
    /*if(isset($_POST['pagers'])){
    	  $string_array=explode('/',$_POST['pagers']);
    	  print_r($string_array);	  
    	  $add_pagination_number=$string_array[5];
    	}*/
    //print_r($get_array);
    $search_results_args['post_type'] = 'property';
    $search_results_args['post_status'] = 'publish';
    $search_results_args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
    /*if(isset($add_pagination_number)){
    		$search_results_args['paged'] = $add_pagination_number;
    	}*/
    $search_results_per_page = $realty_theme_option['search-results-per-page'];
    // Search Results Per Page: Check for Theme Option
    if ($search_results_per_page) {
        $search_results_args['posts_per_page'] = $search_results_per_page;
    } else {
        $search_results_args['posts_per_page'] = 10;
    }
    // Search Results Order
    if (!empty($_GET['orderby'])) {
        $orderby = $_GET['orderby'];
        // By Date (Newest First)
        if ($orderby == 'date-new') {
            $search_results_args['orderby'] = 'date';
            $search_results_args['order'] = 'DESC';
        }
        // By Date (Oldest First)
        if ($orderby == 'date-old') {
            $search_results_args['orderby'] = 'date';
            $search_results_args['order'] = 'ASC';
        }
        // By Price (Highest First)
        if ($orderby == 'price-high') {
            $search_results_args['meta_key'] = 'estate_property_price';
            $search_results_args['orderby'] = 'meta_value_num';
            $search_results_args['order'] = 'DESC';
        }
        // By Price (Lowest First)
        if ($orderby == 'price-low') {
            $search_results_args['meta_key'] = 'estate_property_price';
            $search_results_args['orderby'] = 'meta_value_num';
            $search_results_args['order'] = 'ASC';
        }
        // Random
        if ($orderby == 'random') {
            $search_results_args['orderby'] = 'rand';
        }
    } else {
        $orderby = '';
    }
    /* META & TAX QUERIES: 
    	============================== */
    $meta_query = array();
    $tax_query = array();
    $i = 0;
    foreach ($_GET as $search_key => $search_value) {
        if ($search_key == "orderby" || $search_key == "pageid") {
            break;
        }
        // Check If Key Has A Value
        if ((!empty($search_value) || $search_key == "price_range_min") && $search_key != "orderby" && $search_key != "pageid") {
            // Search Form Mini
            if (isset($_GET['form']) && $_GET['form'] == "mini") {
                $search_parameters = $realty_theme_option['property-search-mini-parameter'];
                $search_fields = $realty_theme_option['property-search-mini-field'];
                $search_position = array_search($search_key, $search_parameters);
                $search_compare = $realty_theme_option['property-search-mini-compare'][$search_position];
                $search_field = $search_fields[$search_position];
            } else {
                $search_parameters = $realty_theme_option['property-search-parameter'];
                $search_fields = $realty_theme_option['property-search-field'];
                $search_position = array_search($search_key, $search_parameters);
                $search_compare = $realty_theme_option['property-search-compare'][$search_position];
                $search_field = $search_fields[$search_position];
            }
            switch ($search_compare) {
                case 'greater_than':
                case 'greather_than':
                    $search_compare = '>=';
                    break;
                    // Do NOT delete "greather_than" typo
                // Do NOT delete "greather_than" typo
                case 'less_than':
                    $search_compare = '<=';
                    break;
                case 'like':
                    $search_compare = 'LIKE';
                    break;
                default:
                    $search_compare = '=';
                    break;
            }
            // Default Fields
            $default_search_fields_array = array('estate_search_by_keyword', 'estate_property_id', 'estate_property_location', 'estate_property_type', 'estate_property_status', 'estate_property_price', 'estate_property_pricerange', 'estate_property_size', 'estate_property_rooms', 'estate_property_bedrooms', 'estate_property_bathrooms', 'estate_property_garages', 'estate_property_available_from');
            // Default Fields
            if (in_array($search_fields[$i], $default_search_fields_array)) {
                switch ($search_fields[$i]) {
                    // Keyword Search
                    case 'estate_search_by_keyword':
                        $search_results_args['s'] = $search_value;
                        break;
                    case 'estate_property_id':
                        if ($realty_theme_option['property-id-type'] == "post_id") {
                            $search_results_args['p'] = $search_value;
                            // Post ID = Default Property ID
                        } else {
                            $meta_query[] = array('key' => 'estate_property_id', 'value' => $search_value);
                        }
                        break;
                    case 'estate_property_price':
                        $meta_query[] = array('key' => 'estate_property_price', 'value' => $search_value, 'type' => 'NUMERIC', 'compare' => $search_compare);
                        break;
                    case 'estate_property_pricerange':
                        $meta_query[] = array('key' => 'estate_property_price', 'value' => array($_GET['price_range_min'], $_GET['price_range_max']), 'type' => 'NUMERIC', 'compare' => 'BETWEEN');
                        break;
                    case 'estate_property_size':
                        $meta_query[] = array('key' => 'estate_property_size', 'value' => $search_value, 'type' => 'NUMERIC', 'compare' => $search_compare);
                        break;
                    case 'estate_property_rooms':
                        $meta_query[] = array('key' => 'estate_property_rooms', 'value' => $search_value, 'type' => 'NUMERIC', 'compare' => $search_compare);
                        break;
                    case 'estate_property_bedrooms':
                        $meta_query[] = array('key' => 'estate_property_bedrooms', 'value' => $search_value, 'type' => 'NUMERIC', 'compare' => $search_compare);
                        break;
                    case 'estate_property_bathrooms':
                        $meta_query[] = array('key' => 'estate_property_bathrooms', 'value' => $search_value, 'type' => 'NUMERIC', 'compare' => $search_compare);
                        break;
                    case 'estate_property_garages':
                        $meta_query[] = array('key' => 'estate_property_garages', 'value' => $search_value, 'type' => 'NUMERIC', 'compare' => $search_compare);
                        break;
                    case 'estate_property_available_from':
                        $meta_query[] = array('key' => 'estate_property_available_from', 'value' => $search_value, 'type' => 'DATE', 'compare' => $search_compare);
                        break;
                    case 'estate_property_location':
                        if ($search_value != "all") {
                            $tax_query[] = array('taxonomy' => 'property-location', 'field' => 'slug', 'terms' => $search_value);
                        }
                        break;
                    case 'estate_property_type':
                        if ($search_value != "all") {
                            $tax_query[] = array('taxonomy' => 'property-type', 'field' => 'slug', 'terms' => $search_value);
                        }
                        break;
                    case 'estate_property_status':
                        if ($search_value != "all") {
                            $tax_query[] = array('taxonomy' => 'property-status', 'field' => 'slug', 'terms' => $search_value);
                        }
                        break;
                    case 'feature':
                        if ($search_value != "all") {
                            $tax_query[] = array('taxonomy' => 'property-features', 'field' => 'slug', 'terms' => $search_value);
                        }
                        break;
                }
                // switch
            } else {
                if (tt_acf_active() && in_array($search_fields[$i], tt_acf_fields_name(tt_acf_group_id_property()))) {
                    // Get Field Type
                    $acf_field_position = array_search($search_fields[$i], tt_acf_fields_name(tt_acf_group_id_property()));
                    $acf_field_type_key = tt_acf_fields_type(tt_acf_group_id_property());
                    $acf_field_type = $acf_field_type_key[$acf_field_position];
                    $type = '';
                    switch ($acf_field_type) {
                        case 'text':
                            $type = 'CHAR';
                            break;
                        case 'number':
                            $type = 'NUMERIC';
                            break;
                        case 'date_picker':
                            $type = 'DATE';
                            break;
                    }
                    // ACF Type: Checkbox & Radio Buttons
                    if ($acf_field_type == 'checkbox') {
                        $meta_query[] = array('key' => $search_key, 'value' => $search_value, 'compare' => 'LIKE');
                    } else {
                        if ($acf_field_type == 'text' || $acf_field_type == 'number' || $acf_field_type == 'date_picker') {
                            $meta_query[] = array('key' => $search_fields[$i], 'value' => $search_value, 'type' => $type, 'compare' => $search_compare);
                        } else {
                            $meta_query[] = array('key' => $search_key, 'value' => $search_value);
                        }
                    }
                }
            }
            // endif ACF;
        }
        // endif !empty($search_value)
        // Dont increase $i for price range, as we are using two parameters (min & max) already
        if ($search_key != "price_range_min") {
            $i++;
        }
    }
    // end foreach()
    // Count meta & tax querie, then set relation for search query
    $meta_count = count($meta_query);
    if ($meta_count > 1) {
        $meta_query['relation'] = 'AND';
    }
    if ($meta_count > 0) {
        $search_results_args['meta_query'] = $meta_query;
    }
    // Count taxonomy queries + set their relation for search query
    $tax_count = count($tax_query);
    if ($tax_count > 1) {
        $tax_query['relation'] = 'AND';
    }
    if ($tax_count > 0) {
        $search_results_args['tax_query'] = $tax_query;
    }
    return $search_results_args;
}