For some reason that's not quite clear, when I add custom query_vars, they become available everywhere without the need of an accessor like global
or get_query_var()
// if your url contains the var http://example.com?document_id=99
// and you add it to $query_vars...
<?php
function filter__query_vars( $query_vars ) {
$query_vars[] = 'document_id';
return $query_vars;
}
add_filter( 'query_vars', 'filter__query_vars' );
// you can reference it anywhere.
/* single.php */
<?php
echo $document_id; // outputs 99. wtf?
Why does this work?