Custom post type search filter to slow

enter image description here

searchresult.php

‘properties’,
‘orderby’ => ‘menu_order’, // we will sort posts by date
‘order’ => ASC, // ASC или DESC
‘posts_per_page’ => -1,
‘paged’ => $paged,
‘meta_query’ => array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘property_transaction’, //Custom Field Name
‘value’ => array(‘buy’, ‘rent’, ‘promotions’),
‘compare’ => ‘IN’
),
array(
‘key’ => ‘location_type’, //Custom Field Name
‘value’ => array(‘local’, ‘international’, ‘both’),
‘compare’ => ‘IN’
),
array(
‘key’ => ‘property_categories’, //Custom Field Name
‘value’ => array(‘residential’, ‘commercial’),
‘compare’ => ‘IN’
),
array(
‘key’ => ‘bedrooms’, //Custom Field Name
‘value’ => 10,
‘type’ => ‘numeric’,
‘compare’ => ‘ ‘price’, //Custom Field Name
‘value’ => array( 0, 999999 ),
‘type’ => ‘numeric’,
‘compare’ => ‘between’
),
array(
‘key’ => ‘size’, //Custom Field Name
‘value’ => array( 0, 6000 ),
‘type’ => ‘numeric’,
‘compare’ => ‘between’
)

)
);

if( isset( $_POST[‘pro_transaction_btn’] ) && $_POST[‘pro_transaction_btn’] ){
$args[‘meta_query’][] = array(
‘key’ => ‘property_transaction’,
‘value’ => $_POST[‘pro_transaction_btn’]
);
}

if ($_POST [‘location_type_btn’] == ‘both’ ) {
$args[‘meta_query’][] = array(
‘key’ => ‘location_type’,
‘value’ => array(‘local’, ‘international’)
);

} elseif ( isset( $_POST[‘location_type_btn’] ) && $_POST[‘location_type_btn’] ) {
$args[‘meta_query’][] = array(
‘key’ => ‘location_type’,
‘value’ => $_POST[‘location_type_btn’]
);
}

if( isset( $_POST[‘property_categories_drop’] ) && $_POST[‘property_categories_drop’] ) {
$args[‘meta_query’][] = array(
‘key’ => ‘property_categories’,
‘value’ => $_POST[‘property_categories_drop’]
);
debug_to_console($_POST[‘property_categories_drop’]);
}
if( isset( $_POST[‘resi_property_type_drop’] ) && 0 != $_POST[‘resi_property_type_drop’] ) {
$args[‘tax_query’][] = array(
‘taxonomy’ => ‘residential_property_type’,
‘field’ => ‘id’,
‘terms’ => array( (int) $_POST[‘resi_property_type_drop’] ),
);
}
if( isset( $_POST[‘comm_property_type_drop’] ) && 0 != $_POST[‘comm_property_type_drop’] ) {
$args[‘tax_query’][] = array(
‘taxonomy’ => ‘commercial_property_types’,
‘field’ => ‘id’,
‘terms’ => array( (int) $_POST[‘comm_property_type_drop’] ),
);
}
if( isset( $_POST[‘property_fitted_drop’] ) && 0 != $_POST[‘property_fitted_drop’] ) {
$args[‘tax_query’][] = array(
‘taxonomy’ => ‘property_fitted’,
‘field’ => ‘id’,
‘terms’ => array( (int) $_POST[‘property_fitted_drop’] ),
);
}
if( isset( $_POST[‘property_furnished_drop’] ) && 0 != $_POST[‘property_furnished_drop’] ) {
$args[‘tax_query’][] = array(
‘taxonomy’ => ‘property_furnished’,
‘field’ => ‘id’,
‘terms’ => array( (int) $_POST[‘property_furnished_drop’] ),
);
}
if(isset($_POST[“bedroom_amount”])){
$args[‘meta_query’][] = array(
‘key’ => ‘bedrooms’,
‘value’ => $_POST[‘bedroom_amount’],
‘type’ => ‘numeric’,
‘compare’ => ‘>=’
);
}
if( isset( $_POST[‘price_min’] ) && $_POST[‘price_min’] || isset( $_POST[‘price_max’] ) && $_POST[‘price_max’] ) {
$args[‘meta_query’][] = array(
‘key’ => ‘price’,
‘value’ => array($_POST[‘price_min’], $_POST[‘price_max’]),
‘type’ => ‘numeric’,
‘compare’ => ‘between’
);
}

if( isset( $_POST[‘size_min’] ) && $_POST[‘size_min’] || isset( $_POST[‘size_max’] ) && $_POST[‘size_max’] ) {
$args[‘meta_query’][] = array(
‘key’ => ‘size’,
‘value’ => array($_POST[‘size_min’],$_POST[‘size_max’]),
‘type’ => ‘numeric’,
‘compare’ => ‘between’
);
}

?>

Myajax:
$(document).ready(function(){
//$(‘#properties-all-list’).hide();
$(function($){
$(‘#filter’).submit(function(){
var filter = $(‘#filter’);
$.ajax({
url:filter.attr(‘action’),
data:filter.serialize(), // form data
type:filter.attr(‘method’), // POST
beforeSend:function(xhr){
filter.find(‘.loader’).show();
},
success:function(data){
filter.find(‘.loader’).hide();
$(‘#properties-all-list’).hide();
$(‘#response’).html(data); // insert data
}
});
return false;
});
});
});

Kindly provide me the solutions

Read more here: Custom post type search filter to slow

Leave a Reply

Your email address will not be published. Required fields are marked *