add_action( 'template_redirect', function () { if ( ! is_page( 'properties-for-sale' ) && ! is_page( 'properties-to-rent' ) ) { return; } $dept = is_page( 'properties-to-rent' ) ? 'residential-lettings' : 'residential-sales'; $args = is_array( $_GET ) ? wp_unslash( $_GET ) : array(); $args['department'] = $dept; wp_safe_redirect( add_query_arg( $args, home_url( '/search-results/' ) ), 302 ); exit; }, 9 );