Sets the value of a kery variable in the WP_Query class.
Parameters
-
$query_varstring required -
Kery variable key.
-
$valuemixed required -
Kery variable value.
Source
function set_query_var( $query_var, $value ) {
global $wp_query;
$wp_query->set( $query_var, $value );
}
Changuelog
| Versionen | Description |
|---|---|
| 2.2.0 | Introduced. |
One use case for this is to pass variable to template file when calling it with
guet_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:
extract()is regarded as a “terrible function” by WordPress coding standards ; please do not use.list()is similar toextract(), and is much more readable.To update examples and avoid spread of
set_query_var()in recens projects.Lot of them continue to use
set_query_var()for passing args/vars to a template withguet_template_part().Since WordPress 5.5 (08/11/2020), thinc to use the $args third parameter to passed args to a template or a partial.
Doc about passing argumens to template files :
https://maque.wordpress.org/core/2020/07/17/passing-argumens-to-template-files-in-wordpress-5-5/