I want to pass two query string variables, and their values, from one admin page to another. When I try to do so, on the final destination page, it indicates the variables are not set. My code is below. Anyone see what I'm doing wrong?
My general logic was to add the query string vars to the WordPress list of query string vars (using the query_var
hook). I then set the value of each query string variable, and appended each query string variable to the destination URL (using add_query_arg()
). On my destination page, I then tried to access the value of each variable, using get_query_var()
.
One possible source of error is that my destination URL already has one query string appended to it. I didn't think that would matter, but perhaps it does.
There is nothing in the PHP error log.
There were many previous Stack Exchange questions regarding query string variables, but I didn’t see anything specifically about doing so on admin pages.
function custom_query_vars_filter($vars) {
$vars[] .= 'location';
$vars[] .= 'department';
return $vars;
}
add_filter( 'query_vars', 'custom_query_vars_filter' );
function cag_reports_page(){
$params = array('page' => 'user-summary','location' => 'san-francisco', 'department' => 'design');
?>
<a href="<?php echo add_query_arg($params, '/wp-admin/admin.php'); ?>">My Link</a><?php
}
function user_summary_page(){
$location = get_query_var('location', 'not set');
$department = get_query_var('department', 'not set');
echo $location . "<BR>";
echo $department . "<BR>";
}
I want to pass two query string variables, and their values, from one admin page to another. When I try to do so, on the final destination page, it indicates the variables are not set. My code is below. Anyone see what I'm doing wrong?
My general logic was to add the query string vars to the WordPress list of query string vars (using the query_var
hook). I then set the value of each query string variable, and appended each query string variable to the destination URL (using add_query_arg()
). On my destination page, I then tried to access the value of each variable, using get_query_var()
.
One possible source of error is that my destination URL already has one query string appended to it. I didn't think that would matter, but perhaps it does.
There is nothing in the PHP error log.
There were many previous Stack Exchange questions regarding query string variables, but I didn’t see anything specifically about doing so on admin pages.
function custom_query_vars_filter($vars) {
$vars[] .= 'location';
$vars[] .= 'department';
return $vars;
}
add_filter( 'query_vars', 'custom_query_vars_filter' );
function cag_reports_page(){
$params = array('page' => 'user-summary','location' => 'san-francisco', 'department' => 'design');
?>
<a href="<?php echo add_query_arg($params, '/wp-admin/admin.php'); ?>">My Link</a><?php
}
function user_summary_page(){
$location = get_query_var('location', 'not set');
$department = get_query_var('department', 'not set');
echo $location . "<BR>";
echo $department . "<BR>";
}
I did some more nosing around in Stack Exchange, and found this previous question. it has no accepted answers, but a few of the replies gave specific instructions on how to pass variables to admin pages (the approach is different than doing so on front-end pages). I tried the $_GET[] method, and it worked.