WP_Query::getpublicWP 1.5.0

Retrieves the value of a query variable.

Method of the class: WP_Query{}

No Hooks.

Returns

Mixed. Contents of the query variable.

Usage

global $wp_query;
$wp_query->get( $query_var, $default_value );
$query_var(string) (required)
Query variable key.
$default_value(mixed)
Value to return if the query variable is not set.
Default: empty string

Changelog

Since 1.5.0 Introduced.
Since 3.9.0 The $default_value argument was introduced.

WP_Query::get() code WP 7.0

public function get( $query_var, $default_value = '' ) {
	return $this->query_vars[ $query_var ] ?? $default_value;
}