Filtered query_vars becomes global. Why does this work?

Within the WP::parse_request() method (src) we locate the query_vars filter:

$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );

and within WP::register_globals() we can see why it becomes globally accessible (src):

// Extract updated query vars back into global namespace.
foreach ( (array) $wp_query->query_vars as $key => $value ) {
    $GLOBALS[ $key ] = $value;
}

where the global $Wp_query has been fed with the query vars from the global $wp object.

Leave a Comment