get_search_query

Retrieves the contents of the search WordPress query variable.

Description

(string) get_search_query( (bool) $escaped = true ); 

The search query string is passed through esc_attr() to ensure that it is safe for placing in an html attribute.

Returns (string)

Parameters (1)

0. $escaped — Optional. (bool) => true
Whether the result is escaped. Default true. Only use when you are later escaping it. Do not use unescaped.

Usage

  1. if ( !function_exists( 'get_search_query' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Whether the result is escaped. Default true. 
  5. // Only use when you are later escaping it. Do not use unescaped. 
  6. $escaped = true; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = get_search_query($escaped); 
  10.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function get_search_query( $escaped = true ) { 
  2. /** 
  3. * Filters the contents of the search query variable. 
  4. * @since 2.3.0 
  5. * @param mixed $search Contents of the search query variable. 
  6. */ 
  7.  
  8. if ( $escaped ) 
  9. $query = esc_attr( $query ); 
  10. return $query;