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.

3 Answers
3

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.

Leave a Reply

Your email address will not be published. Required fields are marked *