get_query_var

Retrieve variable in the WP_Query class.

Description

get_query_var( (string) $var, (string) $default = '' ); 

Parameters (2)

0. $var (string)
The variable key to retrieve.
1. $default — Optional. (string) => ''
Value to return if the query variable is not set. Default empty.

Usage

  1. if ( !function_exists( 'get_query_var' ) ) { 
  2. require_once ABSPATH . WPINC . '/query.php'; 
  3.  
  4. // The variable key to retrieve. 
  5. $var = ''; 
  6.  
  7. // Optional. Value to return if the query variable is not set. Default empty. 
  8. $default = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_query_var($var, $default); 
  12.  

Defined (1)

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

/wp-includes/query.php  
  1. function get_query_var( $var, $default = '' ) { 
  2. global $wp_query; 
  3. return $wp_query->get( $var, $default );