1

I need to add pamarameters to URLs that are read by javascript widgest/gadgets run on the site.

Whenever I just add them e.g. the original URL is http://example.com/blog/page/ and the parameter is called foo with a value called bar.

The new URL becomes: http://example.com/blog/page/?foo=bar

The original URL is working fine, but the new URL is giving a 404. I assume that I need to register any additional parameter so that this works first. Is this true? How can I make new URL parameters not triggering 404s?

4
  • I can't follow your question(sorry), widgets don't have their own URLs. I don't see the connection between widgets and URLs, would you mind going into a bit more detail.
    – t31os
    Commented Mar 4, 2011 at 11:32
  • t31os - I'm talking about some html/javascript widgets here, not Wordpress PHP widgets. So this might be the missing link. It's a pretty general question. A more correct alternative question might be: Why does adding stuff to the query-info part of an URL causes 404 responses by wordpress?
    – hakre
    Commented Mar 4, 2011 at 13:01
  • Oddly pages with query vars seem to only work when the first uses var uses a ? and not an &, which is odd considering the page name is technically the first query var(must have changed in 3.1, i don't remember this occuring in 2.9-3.0).
    – t31os
    Commented Mar 4, 2011 at 17:17
  • @t31os - the site in question is running WP 3.0.3, I'll suggest the owner to upgrade it to 3.0.5 at least.
    – hakre
    Commented Mar 7, 2011 at 13:31

2 Answers 2

0

I think you just need to add it to the query vars

add_filter( 'query_vars', 'my_query_vars' ); 
function my_query_vars( $query_vars ) {     
    $query_vars[] = 'foo';
    return $query_vars;
}
5
  • Just would like to know if this is "think" is a "guess" or a "know". Thanks.
    – hakre
    Commented Mar 4, 2011 at 11:24
  • In this case "Think" = if i remember correctly
    – Bainternet
    Commented Mar 4, 2011 at 11:31
  • Thanks for clarifying. It's something I assumed as well but I just wonder why this is actually triggering a 404. As the vars are not registered, WP shouldn't care at all. I think I need to review that, will report back.
    – hakre
    Commented Mar 4, 2011 at 12:56
  • I did now test your suggestion but adding the query variables did not work. The 404 error still occurs.
    – hakre
    Commented Mar 7, 2011 at 13:29
  • @baked i have done some deeper digging and need some feedback from you, does the 404 happen when using the default permalink structure? If not then you would need to create a rewrite rule to fix it.
    – Bainternet
    Commented Mar 7, 2011 at 16:33
0

I found the answer to my question.

There is no need register query vars for this but instead to take care to not use some of the core query vars as this will break things.

In my case it was the year query variable which caused the 404.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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