[ WordPress.org  ](https://wordpress.org/)

  * [ News  ](https://wordpress.org/news/)
  * [ Showcase  ](https://wordpress.org/showcase/)
  * [ Hosting  ](https://wordpress.org/hosting/)
  * Extend 
    * [ Themes  ](https://wordpress.org/themes/)
    * [ Plugins  ](https://wordpress.org/plugins/)
    * [ Patterns  ](https://wordpress.org/patterns/)
    * [ Blocks  ](https://wordpress.org/blocks/)
    * [ Openverse  ↗  ︎  ](https://openverse.org/)
  * Learn 
    * [ Learn WordPress  ](https://learn.wordpress.org/)
    * [ Documentation  ](https://wordpress.org/documentation/)
    * [ Forums  ](https://wordpress.org/support/forums/)
    * [ Developers  ](https://developer.wordpress.org/)
    * [ WordPress.tv  ↗  ︎  ](https://wordpress.tv/)
  * Community 
    * [ Make WordPress  ](https://make.wordpress.org/)
    * [ Photo Directory  ](https://wordpress.org/photos/)
    * [ Five for the Future  ](https://wordpress.org/five-for-the-future/)
    * [ Events  ](https://events.wordpress.org/)
    * [ Job Board  ↗  ︎  ](https://jobs.wordpress.net/)
  * About 
    * [ About WordPress  ](https://wordpress.org/about/)
    * [ Enterprise  ](https://wordpress.org/enterprise/)
    * [ Gutenberg  ↗  ︎  ](https://wordpress.org/gutenberg/)
    * [ Swag Store  ↗  ︎  ](https://mercantile.wordpress.org/)
  * [ Get WordPress  ](https://wordpress.org/download/)

Search in WordPress.org

[ Get WordPress ](https://wordpress.org/download/)

[ WordPress.org  ](https://wordpress.org/)

[ WordPress Developer Resources ](https://developer.wordpress.org)

add_query_arg()

  * [ Developer Blog  ](https://developer.wordpress.org/news/)
  * [ Code Reference  ](https://developer.wordpress.org/reference/)
  * [ WP-CLI Commands  ](https://developer.wordpress.org/cli/commands/)

  * [ Developer Blog  ](https://developer.wordpress.org/news/)
  * [ Code Reference  ](https://developer.wordpress.org/reference/)
  * [ WP-CLI Commands  ](https://developer.wordpress.org/cli/commands/)

[ Home ](https://developer.wordpress.org) [ Reference
](https://developer.wordpress.org/reference/) [ Functions
](https://developer.wordpress.org/reference/functions/) add_query_arg()

Search

#  add_query_arg(  $args  ):  string

##  In this article

Table of Contents

  * Description 
  * Parameters 
  * Return 
  * More Information 
  * Source 
  * Related 
  * Changelog 
  * User Contributed Notes 

↑  Back to top

Retrieves a modified URL query string.

##  Description

You can rebuild the URL and append query variables to the URL query by using
this function.  
There are two ways to use this function; either a single key and value, or an
associative array.

Using a single key and value:

    
    
    add_query_arg( 'key', 'value', 'http://example.com' );

Using an associative array:

    
    
    add_query_arg( array(
        'key1' => 'value1',
        'key2' => 'value2',
    ), 'http://example.com' );

Omitting the URL from either use results in the current URL being used (the
value of ` $_SERVER['REQUEST_URI'] ` ).

Values are expected to be encoded appropriately with urlencode() or
rawurlencode().

Setting any query variable’s value to boolean false removes the key (see [
remove_query_arg()
](https://developer.wordpress.org/reference/functions/remove_query_arg/) ).

Important: The return value of [ add_query_arg()
](https://developer.wordpress.org/reference/functions/add_query_arg/) is not
escaped by default. Output should be late-escaped with [ esc_url()
](https://developer.wordpress.org/reference/functions/esc_url/) or similar to
help prevent vulnerability to cross-site scripting (XSS) attacks.

##  Parameters

` $key ` string  |  array  required 
    

Either a query variable key, or an associative array of query variables.

` $value ` string  optional

    

Either a query variable value, or a URL to act upon.

` $url ` string  optional

    

A URL to act upon.

##  Return

string  New URL query string (unescaped).

##  More Information

####  Usage

    
    
    // Para