Can't search with multiple words
-
Hi,
I’ve been testing my search with only one word and thought everything was working perfectly fine, until I did a search for 2 words: lorem ipsum. It returned me a 404 error upon clicking the Search Button.
I’m using a URL Rewritting code to change the default ?s=lorem to a friendly /search/lorem
However, it only works for single words. For multiple words, it doesn’t work!
Here is my code:
functions.php
function search_url_rewrite_rule() { if ( is_search() && !empty($_GET['s'])) { wp_redirect(home_url("/".qtrans_getLanguage()."/search/") . urlencode(get_query_var('s'))); exit(); } } add_action('template_redirect', 'search_url_rewrite_rule');
This works perfectly, I get redirected to http://dev.mycompany.com/mysite/en/search/tips
searchform.php
<form method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>/"> <input type="text" class="field" name="s" id="s" value="" /> <input type="submit" class="submit" id="searchsubmit" value="Search" /> </form>
search.php
See PasteBin: http://pastebin.com/5fL97HaPNote: I am using Relevanssi V2.9.10 plugin along with qTranslate.
Example of what works:
Typing tips returns http://dev.mycompany.com/site/en/search/tips
Typing lorem returns http://dev.mycompany.com/site/en/search/loremExample of what does NOT work (returns SERVER ERROR 404 Not found):
Typing lorem ipsum returns http://dev.mycompany.com/site/en/search/lorem+ipsumWould it be the fault of the URL Rewriting?
Thanks!
- The topic ‘Can't search with multiple words’ is closed to new replies.