You don’t need $url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
for getting the current URL to remove the query string.
All you need is remove_query_arg('the_query', false)
. False, means it will use the current URL and your code can be shorten to:
function abc_redirections(){
if(isset($_GET['query_string']) || isset($_GET['query_string_1'])){
$array = array();
if(isset($_GET['query_string']) && (empty($_GET['query_string']) || !is_numeric($_GET['query_string']) || (is_numeric($_GET['query_string']) && $_GET['query_string'] < 1))){
$array[] = "query_string";
}
if(isset($_GET['query_string_1']) && (empty($_GET['query_string_1']) || !is_numeric($_GET['query_string_1']) || (is_numeric($_GET['query_string_1']) && $_GET['query_string_1'] < 1))){
$array[] = "query_string_1";
}
wp_redirect(remove_query_arg($array, false));
}
}
Also, you are right. The page will become slow with the current approach since it will load twice.