Skip to content

Instantly share code, notes, and snippets.

@garretthyder
Forked from daithi-coombes/functions.php
Last active September 18, 2015 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garretthyder/903316be2dbde3fb84f0 to your computer and use it in GitHub Desktop.
Save garretthyder/903316be2dbde3fb84f0 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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment