Skip to content

Instantly share code, notes, and snippets.

@daithi-coombes
Last active September 8, 2018 13:37
Show Gist options
  • Save daithi-coombes/5944849 to your computer and use it in GitHub Desktop.
Save daithi-coombes/5944849 to your computer and use it in GitHub Desktop.
To enable 'price from' and 'price to' search for wordpress [WP Property Plugin](https://usabilitydynamics.com/products/wp-property/forum/topic/price-range-search/)
/**
* Rename these to the form input names you are going to use.
* When you create a new attribute in Properties->Settings->Developer
* the form input name will appear greyed out under the attribute name
*/
define('SPRP_SEARCH_FROM_KEY', 'price_from_per_month');
define('SPRP_SEARCH_TO_KEY', 'price_to_per_month');
function parse_search(){
//vars
if(@$_REQUEST['wpp_search'][SPRP_SEARCH_FROM_KEY])
$wpp_search = $_REQUEST['wpp_search'];
else
$wpp_search = $_POST['wpp_search'];
$from = $wpp_search[SPRP_SEARCH_FROM_KEY];
$to = $wpp_search[SPRP_SEARCH_TO_KEY];
//set price range
if(
isset($wpp_search[SPRP_SEARCH_FROM_KEY]) &&
isset($wpp_search[SPRP_SEARCH_TO_KEY])
){
$_POST['wpp_search']['price'] = "{$from} - {$to}";
//all
if( $_POST['wpp_search']['price']=="-1 - -1" )
$price = "-1";
//any min
if( $from=='-1' )
$price = "0 - {$to}";
//reset price vars
$_POST['wpp_search']['price'] = $price;
$_REQUEST['wpp_search']['price'] = $price;
//any max
if( $to=='-1' ){
$price = "{$from} - -1";
$_POST['wpp_search']['price'] = array();
$_REQUEST['wpp_search']['price'] = array();
$_POST['wpp_search']['price']['min'] = $from;
$_REQUEST['wpp_search']['price']['min'] = $from;
}
//between min and max
if( $to!='-1' && $from!='-1'){
$_POST['wpp_search']['price'] = "{$from} - {$to}";
$_REQUEST['wpp_search']['price'] = "{$from} - {$to}";
}
}
//unset custom form input values
if(@$_REQUEST['wpp_search'][SPRP_SEARCH_FROM_KEY]){
unset($_REQUEST['wpp_search'][SPRP_SEARCH_FROM_KEY]);
unset($_REQUEST['wpp_search'][SPRP_SEARCH_TO_KEY]);
}else{
unset($_POST['wpp_search'][SPRP_SEARCH_FROM_KEY]);
unset($_POST['wpp_search'][SPRP_SEARCH_TO_KEY]);
}
}
parse_search();
@tiberakis
Copy link

Thanks Daithi, where could I call the function from in another theme, if you would like to tell it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment