I am trying to link out from the WP admin to view posts in a specific way.
The url structure for this is example.com/post123/?my-preview=456
/post123/
is the regular permalink for a post. The ?my-preview=456
allows a section of that post to retrieve information based off of the my-preview value.
I understand that WP strips $_GET
parameters from the url, so I tried using add_filter('query_vars','my_query_vars');
and
function my_query_vars($query_vars){
$query_vars[] = 'my-preview';
return $query_vars;
}
On the actual section where I need to get that value, I tried using:
global $wp_query;
var_dump($wp_query->query_vars);
Even with a url like the example above, the 'my-preview' pair is nowhere to be found in the $wp_query->query_vars array.
Am I not doing the correct steps to register an additional query_var for use later on? If I am, why does it not stick around?
EDIT:
I have also tried:
add_action('init', 'add_query_vars');
with
function add_query_vars() {
global $wp;
$wp->add_query_var('my-preview');
}
and wp_die(var_dump(get_query_var('my-preview')));
gives string(0) ""