WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/remove query arg

Contents

Description

Removes an item or list from the query string.

Usage

// individual parameter
<?php remove_query_arg$key$query ?>

// multiple parameters in an array
<?php remove_query_arg( array('$key1''key2''key3'), $query ?>

Parameters

$key
(string|array) (required) Query key or keys to remove.
Default: None
$query
(boolean) (optional) When false uses the $_SERVER value.
Default: false

Return Values

(string) 
New URL query string.

Examples

Assuming we're at the WordPress URL "http://www.example.com/client/?details=value1&type=value2&date=value3"... <?php
// This would output '/client/?type=value2&date=value3'
echo remove_query_arg'details' );

// This would output '/client/'
$arr_params = array( 'details''type''date');
echo 
remove_query_arg$arr_params );
?>
When you want to manipulate a URL that is not of the page your script is in, add the targeted URL in the second parameter as below: <?php
// This would output 'http://www.example.com/2014/03/11/'
echo remove_query_arg'details',  'http://www.example.com/2014/03/11/?details=value1');

// This would output 'http://www.example.com/2014/03/11/?type=value2&date=value3'
echo remove_query_arg'details',  'http://www.example.com/2014/03/11/?details=value1&type=value2&date=value3');

// This would output 'http://www.example.com/2014/03/11/'
$arr_params = array( 'details''type''date');
echo 
remove_query_arg$arr_params'http://www..example.com/2014/03/11/?details=value1&type=value2&date=value3');
?>

Notes

Change Log

Since: 1.5.0

Source File

remove_query_arg() is located in wp-includes/functions.php.

Related

remove_query_artg()

See also index of Function Reference and index of Template Tags.