set_query_var( string $query_var, mixed $value )
Sets the value of a query variable in the WP_Query class.
Parameters
-
$query_var
string Required -
Query variable key.
-
$value
mixed Required -
Query variable value.
Source
File: wp-includes/query.php
.
View all references
function set_query_var( $query_var, $value ) {
global $wp_query;
$wp_query->set( $query_var, $value );
}
Changelog
Version | Description |
---|---|
2.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
One use case for this is to pass variable to template file when calling it with
get_template_part()
.Now in you template you can then call it.
This is a way to pass variables to the called files.
On the a.php file:
On the b.php file:
On the c.php file:
Top ↑
Feedback
IMO: Using extract method can help readability, in my case allowed me not rename variables already in use. On the c.php file:
— By Ivo Vicente —
extract()
is regarded as a “terrible function” by WordPress coding standards; please do not use.list()
is similar toextract()
, and is much more readable. — By crstauf —