WP_Query::get() WordPress Method

The WP_Query::get() method is a quick way to get the results of a WP_Query without having to setup and loop through the query yourself. This is useful for situations where you just need a quick way to get data from your WordPress site.

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

Retrieves the value of a query variable.


Parameters

$query_var

(string)(Required)Query variable key.

$default_value

(mixed)(Optional) Value to return if the query variable is not set.

Default value: ''


Top ↑

Return

(mixed) Contents of the query variable.


Top ↑

Source

File: wp-includes/class-wp-query.php

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

		return $default_value;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.9.0The $default_value argument was introduced.
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More