1. Docs
  2. Developer Guide
  3. Miscellaneous and Snippets
  4. Different URLs For Different Searches

Different URLs For Different Searches

By default there is one page that you use as your ‘Property Search’ page. This is specified in the ‘General’ section of the Property Hive settings area.

Sometimes you want to offer the users more friendly URLs. For example you might want to use /sales as the URL for displaying properties for sale, and /lettings to display properties to rent.

The above scenario can be achieved by adding the following to your theme’s functions.php file:

// 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' );
// 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[] = 'office';
    $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;

Important: Once you’ve added the above, remember to go into ‘Settings > Permalinks‘ and just hit ‘Update’ to force the rewrites to take effect.