Support » Fixing WordPress » Custom URL variables getting munged

  • I need to pass some strings to a page, so I’m loading them into the URL and setting up a query_vars filter to make them available on the destination page.

    I added this code to my functions script:

    function vrtheme_queryvars( $qvars )
    	$get_vars = array('title','movie','remarks','auto');
    	foreach ($get_vars as $v) $qvars[] = $v;
    	return $qvars;
    add_filter('query_vars', 'vrtheme_queryvars' );

    And the receiving page gets them, it’s just that all the spaces have been stripped out. I’ve tried both urlencode and rawurlencode to load the URL, but the spaces in the strings don’t make it to the destination page. (The strings are a couple of pieces of text along with the URL of an audio file to play)

    Is there something I can do to preserve the spaces in the strings?

    Or maybe query_vars isn’t the bast way to do this…

Viewing 6 replies - 1 through 6 (of 6 total)
  • I haven’t gotten any replies on this, so I wondered if it was only me seeing this. I tested the functionality on another WordPress site I have and, indeed it works fine: all the spaces in the strings are preserved.

    So, it’s only this one installation that’s got this issue. I tried disabling all the plugins, inspecting any .htaccess files that might be altering the query string, messed around with the permalinks settings, and yet I am no closer to seeing why this particular site is altering the query string.

    anybody has some ideas where else to look, I’d appreciate it!

    xnau, have you had any luck with this? I’m having the same issue.

    I want to pass something like:

    but WordPress makes it:

    I need to display variables with spaces but they get stripped out. I’ve tried %20 and + but neither works.

    Does anyone know if there is a way to tell WordPress to preserve the original formatting in URLs?

    Thanks in advance.


    This issue was never resolved. I had to use a workaround.

    The reason no-one else got in on this is that there’s something in particular about this one site that’s causing this. All my other WordPress sites are leaving the GET variables untouched. Doesn’t seem to be the htaccess, so I’m not sure what the issue is, and I haven’t had the time to figure it out.

    My workaround was to use a placeholder character (not %20 or +, I used ! ) for the spaces and then restore the spaces on the receiving end. Messy little kludge but it works and life can go on…

    If anybody has a clue as to why this is happening, that would be quite helpful!

    Thanks, xnau. I may need to go the same route. Could you elaborate on how you restored the spaces using ! as a placeholder character?

    Thanks again.

    I went pretty simple on that: just use str_replace(‘ ‘,’!’,$string) on your strings as you build them into the GET string–then again str_replace(‘!’,’ ‘,$string) when you read them out.

    OK, thanks. I can (and probably will) take that approach to replace a particular character (for me, spaces are most important).

    The bigger issue though is that WordPress not only strips out spaces, but any special characters (%, !, +, etc.) so the str_replace approach isn’t very scalable if you want to allow multiple special characters.

    Anyway, sounds like this issue is not universal, so I need to try to troubleshoot why my site is doing this. I’ll let you know if I figure that out.

    Thanks again.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom URL variables getting munged’ is closed to new replies.