set_query_var( string $var, mixed $value )

Set query variable.

Description Description

Parameters Parameters


(string) (Required) Query variable key.


(mixed) (Required) Query variable value.

Top ↑

Source Source

File: wp-includes/query.php

function set_query_var( $var, $value ) {
	global $wp_query;
	$wp_query->set( $var, $value );

Top ↑

Changelog Changelog

Version Description
2.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stode

    One use case for this is to pass variable to template file when calling it with get_template_part().

    // When calling a template with get_template_part()
    set_query_var('my_form_id', 23);

    Now in you template you can then call it.

    // Inside my-form-template.php
    $my_form_id = get_query_var('my_form_id');

You must log in before being able to contribute a note or feedback.