Last active
September 8, 2018 13:37
-
-
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/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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(); |
Author
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
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
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:
Dashboard -> Properties -> Settings -> DeveloperProperty Attributescreate two rows forsearch fromandsearch toSearch InputofDropdown Selectionwith values of: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 Propertydenaliand in your child themesfunction.phpfile add the above code (start file with<?phpand a new line). More on creating child themes: http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Themewp-content/themes/denali/functions.php. Please note if you take this option you will have to re-insert this code EVERY timeWP Propertyplugin orDenalitheme 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 inputPrice Fromthen the input name will beprice_from.Using both those input names, place them in the above code where it says
price_from_per_monthandprice_to_per_monthrespectively.Example
Say I create two inputs called
From PriceandTwo Pricethen the input names will befrom_priceandto_price, the above code will look like: