Retrieve a modified URL query string.

You can rebuild the URL and append a new query variable to the URL query by using this function. You can also retrieve the full URL with query data.

Adding a single key & value or an associative array. Setting a key value to an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER value. Additional values provided are expected to be encoded appropriately with urlencode() or rawurlencode().

Signature

add_query_arg()

Return

(string) New URL query string.

Source

function add_query_arg() {
	$args = func_get_args();
	if ( is_array( $args[0] ) ) {
		if ( count( $args ) < 2 || false === $args[1] )
			$uri = $_SERVER['REQUEST_URI'];
		else
			$uri = $args[1];
	} else {
		if ( count( $args ) < 3 || false === $args[2] )
			$uri = $_SERVER['REQUEST_URI'];
		else
			$uri = $args[2];
	}

	if ( $frag = strstr( $uri, '#' ) )
		$uri = substr( $uri, 0, -strlen( $frag ) );
	else
		$frag = '';

	if ( 0 === stripos( $uri, 'http://' ) ) {
41 more lines...
WP Trac GitHub

Link here