• 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thelusiv

    (@thelusiv)

    Can anyone help me with this? It seems like a simple problem, but I’m having trouble sorting it out still. Is it perhaps something about the URL rewriting going on to make pretty URLs using page slugs? I don’t know enough about how WordPress does this. Guess I need to start poking through the code. Any suggestions would be greatly appreciated…

    Thread Starter thelusiv

    (@thelusiv)

    The problem seems to be related to the name parameter. I’m guessing that this is already in use by WordPress to look up pages or posts or something. I guess I need some sort of custom rewrite rule…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting all the URL variables in a WordPress page’ is closed to new replies.