3

I'm passing a GET variable at the end of my URL's as my search parameter. When I do a regular search, everything works fine:

www.mysite.com/?find=my+search

However, when I click over to the second page of results, Wordpress strips the search query of spaces and converts the URL to:

www.mysite.com/page/2/?find=mysearch

I'm using the WP-PageNavi plugin and checked that the URL for the next page is correct: www.mysite.com/page/2/?find=my+search

My permalinks structure is: /%post_id%/%postname%/

Has anyone had experience with Wordpress stripping out the spaces from your URL when using custom permalinks?

Thanks in advance for any help! I haven't been able to find much online about this except a few other people with the same problem.

4
  • What plugins (give us a full list) are you running? Another plugin you've got on your site might be causing the problem. The fact that you're using a non-standard query variable (WordPress searches use ?s=) suggests that it's being incorrectly added to the list of "safe" query vars for WordPress.
    – EAMann
    Jun 21, 2011 at 20:19
  • I deactivated all plugins except WP-PageNavi, and it was still stripping the spaces. I have a complex custom search on my site and needed to override the Wordpress default search functionality, which is why I'm using the non-standard query variable. I tried adding my ?find variable to the list of safe query vars, but didn't have any luck with it. Could you provide an example? Thanks for the response!
    – Andy Cook
    Jun 22, 2011 at 3:04
  • @Andy Cook, did you find an answer to this? The exact same thing is happening to me using the WP-PageNavi plugin.
    – MathSmath
    Jul 12, 2011 at 15:57
  • I'm having the same problem, did anyone ever get to the bottom of this? I can see using httpfox that there's a 301 redirect that happens after I click to get the second page of results, and the redirect URL has the spaces stripped out. I've tried EAMann's solution and it made no difference. Dec 9, 2011 at 10:37

3 Answers 3

2

Not sure exactly how you're adding "find" to the list of query variables, but this is the method you're supposed to use:

function wpa_20565_query_vars( $public_vars ) {
    $public_vars[] = 'find';
    return $public_vars;
}
add_filter( 'query_vars', 'wpa_20565_query_vars' );

I use that to add custom pagination for my custom post types and custom filters for various other uses. It should make WP recognize and ignore the "find" query variable.

My next recommendation would be to enable the Debug Bar plugin and see what query it is WordPress is actually seeing. I'd also love to see the code you're using to create the "next page" link that's giving you a bad URL. It might also be partly responsible for the problems.

0

I had this exact problem and was able to fix it by adding a trailing "/" to the url. After that it kept the spacing.

0

Try the fix here

If the fix does not work as stated, I posted a comment that works with WP e-Commerce Version 3.8.9.4. Check the page’s comments

2
  • 1
    That fix seems specific to WP eCommerce. The OP stated that there are no plugins beside WP-Pagenavi. Can you explain why you think this is relevant, or how to adapt the code to other circumstances?
    – s_ha_dum
    Jan 12, 2013 at 15:01
  • Anthony, an Answer should be more than a single link. And if you posted a solution over there, why not post it here too?
    – brasofilo
    Jan 12, 2013 at 16:58

Your Answer

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

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