Query arg not available on init

I'm adding my query arg as such:

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

And when I do:

add_action( 'init', function() {
    $string = get_query_var( 'my_query_var' );
    echo( $string );
});

It's not available, yet if I hook very, very late, like loop_start, it's there. What exactly am I missing? The string I passed is there if I inspect $_GET.

Topic query-variable Wordpress

Category Web


The query_vars filter does not run until after init. The earliest hook you can use get_query_var() is parse_request, which runs after init, but before send_headers, wp, template_redirect, and template_include.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.