I wanted to add a custom query variable for my wordpress website.
I have tried adding it using this:
function themeslug_query_vars( $qvars ) {
$qvars[] = 'custom_query_var';
return $qvars;
}
add_filter( 'query_vars', 'themeslug_query_vars' , 10, 1 );
Also tried this one:
function themeslug_query_vars() {
add_rewrite_tag('%id%', '([0-9])');
}
add_action('init', 'themeslug_query_vars', 10, 0);
I checked if my custom query var is added using this:
global $wp_query;
var_dump($wp_query->query_vars);
But no luck. Could someone help me with this problem? Thanks!