W3cubDocs

/WordPress

WP_Query::get( string $query_var, mixed $default_value = ): mixed

Retrieves the value of a query variable.

Parameters

$query_varstringrequired
Query variable key.
$default_valuemixedoptional
Value to return if the query variable is not set.

Default:''

Return

mixed Contents of the query variable.

Source

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

	return $default_value;
}

Changelog

Version Description
3.9.0 The $default_value argument was introduced.
1.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_query/get