WP_Query::get( string $query_var, mixed $default_value = '' ): mixed
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:
''
Return
mixed Contents of the query variable.
Source
File: wp-includes/class-wp-query.php
.
View all references
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. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Check if it’s Custom post type query:
Usage scenario: if it’s a query for CPT recipe, it’s not the main query, it’s not admin -> say Hello! before it starts