Last active
February 16, 2026 10:24
-
-
Save propertyhive/60d2b244f43ca49081b43f4578f459ba to your computer and use it in GitHub Desktop.
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
| // Setup two separate URLs | |
| add_action( 'init', 'ph_add_rewrite_rules' ); | |
| function ph_add_rewrite_rules() | |
| { | |
| global $wp_rewrite; | |
| // Setup Sales URL '/sales/' | |
| add_rewrite_rule( "sales/?$", "index.php?post_type=property&department=residential-sales", 'top' ); | |
| add_rewrite_rule( "sales/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=property&department=residential-sales" . '&paged=$matches[1]', 'top' ); | |
| // Setup Lettings URL '/lettings/' | |
| add_rewrite_rule( "lettings/?$", "index.php?post_type=property&department=residential-lettings", 'top' ); | |
| add_rewrite_rule( "lettings/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=property&department=residential-lettings" . '&paged=$matches[1]', 'top' ); | |
| // Setup Lettings URL '/commercial/' | |
| add_rewrite_rule( "commercial/?$", "index.php?post_type=property&department=commercial", 'top' ); | |
| add_rewrite_rule( "commercial/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=property&department=commercial" . '&paged=$matches[1]', 'top' ); | |
| } | |
| // Add support for Property Hive custom query_vars | |
| add_filter( 'query_vars', 'add_query_vars' ); | |
| function add_query_vars( $query_vars ) | |
| { | |
| $query_vars[] = 'department'; | |
| $query_vars[] = 'address_keyword'; | |
| $query_vars[] = 'marketing_flag'; | |
| $query_vars[] = 'minimum_price'; | |
| $query_vars[] = 'maximum_price'; | |
| $query_vars[] = 'minimum_rent'; | |
| $query_vars[] = 'maximum_rent'; | |
| $query_vars[] = 'minimum_bedrooms'; | |
| $query_vars[] = 'minimum_floor_area'; | |
| $query_vars[] = 'maximum_floor_area'; | |
| $query_vars[] = 'property_type'; | |
| $query_vars[] = 'commercial_property_type'; | |
| $query_vars[] = 'officeID'; | |
| $query_vars[] = 'view'; | |
| $query_vars[] = 'radius'; | |
| $query_vars[] = 'pgp'; | |
| // append here any other query string parameters you might be using | |
| return $query_vars; | |
| } | |
| // Convert all query_vars found to $_GET and $_REQUEST parameters as this is what the search form and main property query are based off | |
| add_action( 'parse_request', 'setup_get' ); | |
| function setup_get($wp_query) | |
| { | |
| foreach ($wp_query->query_vars as $name => $value) | |
| { | |
| if (!empty($value) && $name != 'name') | |
| { | |
| $_GET[$name] = $value; | |
| $_REQUEST[$name] = $value; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment