Getting all the URL variables in a WordPress page
-
Hi, I’m curious to know how I can get all the URL variables in a WordPress page. For instance, I have a newsletter subscription request landing page with a URL like this:
http://mysite.com/newsletter/subscription-request
When a user requests to subscribe, the page is passed some of the form variables, like this:
http://mysite.com/newsletter/subscription-request?address=subscriber%40yahoo%2Ecom&name=Joe%20Subscriber&code=3
I have some extra functions in my theme’s functions.php like this:add_filter(‘query_vars’, ‘parameter_queryvars’ );
function parameter_queryvars( $qvars )
{
$qvars[] = ‘address’;
$qvars[] = ‘name’;
$qvars[] = ‘code’;
return $qvars;
}function get_queryvar($varname)
{
global $wp_query;
if (isset($wp_query->query_vars[$varname]))
{
return $wp_query->query_vars[$varname];
}
return NULL;
}I have installed the plugin “Allow PHP in posts and pages” to facilitate calling the function
get_queryvar
, so that I can do things like this in the page:[php]
$address = get_queryvar(“address”);
if ($address != NULL) print $address; else print “unspecified”;
[/php]This all works fine, as long as I only have the “?address=…” variable in the request URL. The issue is that whenever a URL with more than one variable in it is passed to WordPress, I get a “Page not found – Sorry, but you are looking for something that isn’t here.” error.
Why is this error present? Is it something about the & character in the URL? How can I avoid this error so that the page can use all the variables?
- The topic ‘Getting all the URL variables in a WordPress page’ is closed to new replies.