query_vars WordPress Filter Hook

The query_vars hook allows you to add custom query variables to the WordPress URL. This can be useful for passing information to your scripts or plugins.

apply_filters( 'query_vars', string[] $public_query_vars ) #

Filters the query variables allowed before processing.


Description

Allows (publicly allowed) query vars to be added, removed, or changed prior to executing the query. Needed to allow custom rewrite rules using your own arguments to work, or any other custom query variables you want to be publicly available.


Top ↑

Parameters

$public_query_vars

(string[])The array of allowed query variable names.


Top ↑

More Information

This filter allows query vars to be added, removed, or changed prior to executing the query.

Top ↑

Example


function myplugin_query_vars( $qvars ) {
	$qvars[] = 'custom_query_var';
	return $qvars;
}
add_filter( 'query_vars', 'myplugin_query_vars' );


Top ↑

Source

File: wp-includes/class-wp.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
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.