query_vars
query_vars is a filter on the query variables used by the WP_Query class (and stored in $wp_request->public_query_vars).
The initial array consists of the following query variables:
mppostswcatwithcommentsssearchexactsentencedebugcalendarpagepagedmoretbpbauthororderorderbyyearmonthnumdayhourminutesecondnamecategory_namefeedauthor_namestaticpagenamepage_iderrorcomments_popupattachmentattachment_idsubpostsubpost_idpreview
Your hook would accept an array, add an item to the array, and return the array.
function add_my_query_var($vars) {
$vars[] = 'my_var';
return $vars;
}
add_filter('query_vars', 'add_my_query_var');
Context:
File: wp-includes/classes.php
$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
This hook is a filter which means that information is passed through it, and then used by WordPress. Your function needs to accept that information, and return it. Using add_filter('query_vars', 'your_function'); helps you to remember this distinction. When you are passing an ID, it is assumed that you will return the ID as it was given to you. With filters that pass strings or arrays, you may manipulate the information before passing it along.