WordPress at a glance
function is not described

_remove_qs_args_if_not_in_url() WP 3.4.0

Removes arguments from a query string if they are not present in a URL DO NOT use this in plugin code.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

String. The altered query string

Usage

_remove_qs_args_if_not_in_url( $query_string, $args_to_check, $url );
$query_string(string) (required)
-
$args_to_check(array) (required)
-
$url(string) (required)
-

Changelog

Since 3.4.0 Introduced.

Code of _remove_qs_args_if_not_in_url() WP 5.7.2

<?php
function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) {
	$parsed_url = parse_url( $url );

	if ( ! empty( $parsed_url['query'] ) ) {
		parse_str( $parsed_url['query'], $parsed_query );

		foreach ( $args_to_check as $qv ) {
			if ( ! isset( $parsed_query[ $qv ] ) ) {
				$query_string = remove_query_arg( $qv, $query_string );
			}
		}
	} else {
		$query_string = remove_query_arg( $args_to_check, $query_string );
	}

	return $query_string;
}