Update search query.

This commit is contained in:
Hoang Huu 2019-10-29 14:25:28 +07:00
parent 3bfc2cb35f
commit 327a3aa1c4
3 changed files with 45 additions and 8 deletions

View File

@ -291,7 +291,7 @@ class Opalestate_Property_MetaBox {
[ [
'name' => esc_html__( 'Built year', 'opalestate-pro' ), 'name' => esc_html__( 'Built year', 'opalestate-pro' ),
'id' => $prefix . 'builtyear', 'id' => $prefix . 'builtyear',
'type' => 'text_date', 'type' => 'text',
'description' => esc_html__( 'Enter built year', 'opalestate-pro' ), 'description' => esc_html__( 'Enter built year', 'opalestate-pro' ),
'before_row' => '<div class="row-group-features group-has-three group-property-info clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Property Information', 'opalestate-pro' ) ) . '</h3>', 'before_row' => '<div class="row-group-features group-has-three group-property-info clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Property Information', 'opalestate-pro' ) ) . '</h3>',

View File

@ -145,14 +145,13 @@ class OpalEstate_Search {
} }
$sarg = apply_filters( 'opalestate_search_field_query_' . $key, $fieldquery ); $sarg = apply_filters( 'opalestate_search_field_query_' . $key, $fieldquery );
$metaquery[] = $sarg; $metaquery[] = $sarg;
} }
} }
$args['meta_query'] = array_merge( $args['meta_query'], $metaquery ); $args['meta_query'] = array_merge( $args['meta_query'], $metaquery );
} }
if ( $search_min_price != '' && $search_min_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) { if ( $search_min_price != '' && $search_max_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) {
if ( $search_min_price ) { if ( $search_min_price ) {
array_push( $args['meta_query'], [ array_push( $args['meta_query'], [
@ -195,7 +194,7 @@ class OpalEstate_Search {
] ); ] );
} }
if ( $search_min_area != '' && $search_min_area != '' && is_numeric( $search_min_area ) && is_numeric( $search_max_area ) ) { if ( $search_min_area != '' && $search_max_area != '' && is_numeric( $search_min_area ) && is_numeric( $search_max_area ) ) {
array_push( $args['meta_query'], [ array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize', 'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
'value' => [ $search_min_area, $search_max_area ], 'value' => [ $search_min_area, $search_max_area ],
@ -237,9 +236,9 @@ class OpalEstate_Search {
$ksearchs = []; $ksearchs = [];
if ( isset( $_REQUEST['opalsortable'] ) && ! empty( $_REQUEST['opalsortable'] ) ) { if ( isset( $_REQUEST['opalsortable'] ) && ! empty( $_REQUEST['opalsortable'] ) ) {
$ksearchs = explode( "_", $_REQUEST['opalsortable'] ); $ksearchs = explode( '_', $_REQUEST['opalsortable'] );
} elseif ( isset( $_SESSION['opalsortable'] ) && ! empty( $_SESSION['opalsortable'] ) ) { } elseif ( isset( $_SESSION['opalsortable'] ) && ! empty( $_SESSION['opalsortable'] ) ) {
$ksearchs = explode( "_", $_SESSION['opalsortable'] ); $ksearchs = explode( '_', $_SESSION['opalsortable'] );
} }
if ( ! empty( $ksearchs ) && count( $ksearchs ) == 2 ) { if ( ! empty( $ksearchs ) && count( $ksearchs ) == 2 ) {
@ -248,8 +247,46 @@ class OpalEstate_Search {
$args['order'] = $ksearchs[1]; $args['order'] = $ksearchs[1];
} }
$args = apply_filters( 'opalestate_get_search_results_query_args', $args ); $metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
foreach ( $metas as $meta ) {
if ( $meta['id'] == OPALESTATE_PROPERTY_PREFIX . 'areasize' ) {
continue;
}
$request = str_replace( OPALESTATE_PROPERTY_PREFIX, '', $meta['id'] );
$setting_search_type = opalestate_options( $meta['id'] . '_search_type', 'select' );
if ( 'range' === $setting_search_type ) {
$min_request = isset( $_GET[ 'min_' . $request ] ) ? sanitize_text_field( $_GET[ 'min_' . $request ] ) : '';
$max_request = isset( $_GET[ 'max_' . $request ] ) ? sanitize_text_field( $_GET[ 'max_' . $request ] ) : '';
if ( $min_request != '' && $max_request != '' && is_numeric( $min_request ) && is_numeric( $max_request ) ) {
array_push( $args['meta_query'], [
'key' => $meta['id'],
'value' => [ $min_request, $max_request ],
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
] );
} elseif ( $min_request != '' && is_numeric( $min_request ) ) {
array_push( $args['meta_query'], [
'key' => $meta['id'],
'value' => $min_request,
'compare' => '>=',
'type' => 'NUMERIC',
] );
} elseif ( $max_request != '' && is_numeric( $max_request ) ) {
array_push( $args['meta_query'], [
'key' => $meta['id'],
'value' => $max_request,
'compare' => '<=',
'type' => 'NUMERIC',
] );
}
}
}
$args = apply_filters( 'opalestate_get_search_results_query_args', $args );
$query = new WP_Query( $args ); $query = new WP_Query( $args );
wp_reset_postdata(); wp_reset_postdata();

View File

@ -238,7 +238,7 @@ class Opalestate_Property_MetaBox_Submission {
[ [
'name' => esc_html__( 'Built year', 'opalestate-pro' ), 'name' => esc_html__( 'Built year', 'opalestate-pro' ),
'id' => $prefix . 'builtyear', 'id' => $prefix . 'builtyear',
'type' => 'text_date', 'type' => 'text',
'description' => esc_html__( 'Enter built year', 'opalestate-pro' ), 'description' => esc_html__( 'Enter built year', 'opalestate-pro' ),
'before_row' => '<div id="opalestate-submission-information" class="opalestate-tab-content"><div class="field-row-2">', 'before_row' => '<div id="opalestate-submission-information" class="opalestate-tab-content"><div class="field-row-2">',