First of all, one never should rely on raw $_REQUEST
: believe me, this is a security issue.
PHP has 2 functions: filter_input
and filter_input_array
that helps you to sanitize your request data.
In addition, in your request dump I don’t see any $_REQUEST['custom_bath']
, but you are using that value, that can be a cause for the issue. You should check that a variable is setted before use it.
Using my suggestions your code becomes something like this
$args = array(
'custom_textarea' => FILTER_SANITIZE_STRING,
'custom_price' => FILTER_VALIDATE_INT,
'custom_price1' => FILTER_VALIDATE_INT,
'custom_beds' => FILTER_SANITIZE_STRING,
'custom_bath' => FILTER_SANITIZE_STRING,
'custom_garage' => FILTER_SANITIZE_STRING
);
$get = filter_input_array( INPUT_GET, $args, TRUE );
$post = filter_input_array( INPUT_POST, $args, TRUE );
$request = array_merge( $get, $post );
$query_args = array( 'relation' => 'OR' );
if ( ! empty( $request['custom_textarea'] ) ) {
$query_args[] = array(
'key' => 'custom_textarea',
'value' => "%{$request['custom_textarea']}%",
'compare' => 'LIKE'
);
}
if ( ! empty( $request['custom_price'] ) && ! empty($request['custom_price1']) ) {
$query_args[] = array(
'key' => 'custom_price',
'value' => array( "{$request['custom_price']}", "{$request['custom_price1']}" ),
'compare' => 'BETWEEN',
'type' => 'SIGNED'
);
}
if ( ! empty( $request['custom_beds'] ) ) {
$query_args[] = array(
'key' => 'custom_beds',
'value' => "{$request['custom_beds']}",
);
}
if ( ! empty( $request['custom_bath'] ) ) {
$query_args[] = array(
'key' => 'custom_bath',
'value' => "{$request['custom_bath']}",
);
}
if ( ! empty( $request['custom_garage'] ) ) {
$query_args[] = array(
'key' => 'custom_garage',
'value' => "{$request['custom_garage']}",
);
}
$query = new WP_Query( $query_args );