remove_query_arg

Removes an item or items from a query string.

Description

(string) remove_query_arg( (string|array) $key, (bool) $query = false ); 

Returns (string)

New URL query string.

Parameters (2)

0. $key (string|array)
Query key or keys to remove.
1. $query — Optional. (bool) => false
When false uses the current URL. Default false.

Usage

  1. if ( !function_exists( 'remove_query_arg' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Query key or keys to remove. 
  5. $key = null; 
  6.  
  7. // Optional. When false uses the current URL. Default false. 
  8. $query = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = remove_query_arg($key, $query); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function remove_query_arg( $key, $query = false ) { 
  2. if ( is_array( $key ) ) { // removing multiple keys 
  3. foreach ( $key as $k ) 
  4. $query = add_query_arg( $k, false, $query ); 
  5. return $query; 
  6. return add_query_arg( $key, false, $query );