This commit is contained in:
Hoang Huu
2020-06-16 17:34:51 +07:00
parent e2db40a211
commit 22c65f696a
4 changed files with 42 additions and 25 deletions

View File

@@ -77,11 +77,19 @@ class OpalEstate_Search {
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] = [
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
if ( is_array( $_GET['location'] ) ) {
$tax_query[] = [
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['location'] ),
];
} else {
$tax_query[] = [
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
}
}
if ( isset( $_GET['state'] ) && $_GET['state'] != -1 ) {
@@ -101,11 +109,19 @@ class OpalEstate_Search {
}
if ( isset( $_GET['city'] ) && $_GET['city'] != -1 ) {
$tax_query[] = [
'taxonomy' => 'opalestate_city',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['city'] ),
];
if ( is_array( $_GET['city'] ) ) {
$tax_query[] = [
'taxonomy' => 'opalestate_city',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['city'] ),
];
} else {
$tax_query[] = [
'taxonomy' => 'opalestate_city',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['city'] ),
];
}
}
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
@@ -165,6 +181,8 @@ class OpalEstate_Search {
];
}
$tax_query = apply_filters( 'opalestate_search_results_tax_query', $tax_query );
if ( $tax_query ) {
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );