There are a million posts on the topic in this stack exchange, and yet for some reason I cannot get this to work for me. I wonder what I'm doing wrong?

In my functions.php I define this:

add_filter('query_vars', 'add_quote_query_vars');
function add_quote_query_vars($qv){
    $qv[] = 'xx-quote';
    return $qv;

Then later, on front_page.php I provide a link that embeds this into the URL:

echo  '<a href="'.add_query_arg('xx-quote', $quote->ID).'">';

Two things go wrong. 1: if, on my template page I print_r($wp_query->query_vars);, my 'xx-quote' doesn't appear in the list 2: as soon as I actually try to include that in the URL (by clicking the link, the URL is http://mysite.com/blog/?xx-quote=555) I'm taken to an archive page, rather than the expected front page.

What's interesting about #2 is that as soon as I remove the query_vars filter and click the link again, I'm taken correctly to the front page as expected.

Am I just not understanding the role of the query_vars? Is this expected behaviour? Or am I calling the filter at the wrong time (I've tried wrapping it in an init action, or even bare inside functions.php)?

I know I can just ignore all this, since I'm dealing with the front_page.php anyway, and just use $_REQUEST['xx-quote'] but that doesn't seem like a best practice at all, and I'm trying to do it "the WordPress way"...

Needless to say, the following code produces no results:

global $wp_query;
echo $wp_query->query_vars['xx-quote'];

And that is the basis of my confusion. I've read all the related posts on this SE and I seem to be doing everything right. Clearly I'm not - what's gone wrong?


I was experiencing a similar problem and traced it back to Yoast's WordPress SEO plugin. This is a very popular plugin, so I wanted to post my fix. If you are running this plugin, do the following:

  1. Navigate to SEO > Permalinks
  2. Is "Redirect ugly URL's to clean permalinks" checked?
  3. If so, scroll down to the input field labelled "Other variables not to clean:" and enter the parameter(s) you wish to allow.

That fixed it for me.

| improve this answer | |

From quick test with your filter active last test snippet works just fine for me. Also I don't get redirected from home page if there.

So it's not your approach that is wrong, but something seems to break it.

| improve this answer | |
  • Thanks for checking. That's what I figured as well, which is why I'm posting this question. Can anyone think of what is breaking this code? Just from your experience? – Tom Auger Jun 28 '11 at 17:49
  • @Tom Auger not really. It doesn't seem to be WP bug (it rarely is) so no place to even start guessing. Strip install to bare minimum (no plugins running, default theme), see if it works, then debug from there. – Rarst Jun 28 '11 at 17:52
  • Okay, will do. If I get a solution that I can document, I'll follow up here for anyone else that might run into the situation. It's got to be SOMETHING. – Tom Auger Jun 30 '11 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.