Skip to content

Instantly share code, notes, and snippets.

@daithi-coombes
Last active September 8, 2018 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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();
@daithi-coombes
Copy link
Author

This gist is in response to this forum thread:
https://usabilitydynamics.com/products/wp-property/forum/topic/price-range-search/

Installation

Create Form Inputs

Navigate to:

  1. Dashboard -> Properties -> Settings -> Developer
  2. In Property Attributes create two rows for search from and search to
  3. Give both Search Input of Dropdown Selection with values of:
0,100,200,300,400,500,600,700,800

Use This Code

There are 2 ways to use this code, one is the best option but slightly more technical, the other is quick and messy but will break when you update WP Property

  1. Preferred option: Create a child theme of denali and in your child themes function.php file add the above code (start file with <?php and a new line). More on creating child themes: http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme
  2. Add the above exactly code as is to the end of wp-content/themes/denali/functions.php. Please note if you take this option you will have to re-insert this code EVERY time WP Property plugin or Denali theme is updated.

Usage

When you create the 2 inputs above, in Dashboard -> Properties -> Settings -> Developer, under the name of the input will be a similar name with _ instead of spaces. For example, if you name the input Price From then the input name will be price_from.

Using both those input names, place them in the above code where it says price_from_per_month and price_to_per_month respectively.

Example

Say I create two inputs called From Price and Two Price then the input names will be from_price and to_price, the above code will look like:

define('SPRP_SEARCH_FROM_KEY', 'from_price');
define('SPRP_SEARCH_TO_KEY', 'to_price');

Copy link

ghost commented Oct 24, 2013

Thanks for the solution but for example if i need search properties of 1,000,000 and more? how i can add this value opcion and that the search works, thanks fo the help

@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