2

My default search query:

example.com/search/?search_text=keyword

What I want to transform it:

example.com/search/keyword

So I added this to my function.php

add_rewrite_rule('^search/([^/]*)?','index.php?pagename=search&search_text=$matches[1]','top');

Works fine for english alphabet but whenever I search a keyword in my language like this:

example.com/search/kırmızı

The title of the page becomes: k%C4%B1rm%C4%B1z%C4%B1 and no results returned.

Let me know if you need more details.

2
+50

This is happening due to encoding. I assume you have a function in your search page, which you get and use search_text inside that template. You should decode the URL before doing so.

The urldecode() function would be what you are looking for. Your string is also UTF-8 encoded, so this is what you are going to need:

$string = utf8_decode( urldecode( $_GET['search_text'] ) );

Now you can use the decoded string in your search.

  • Your response showed me the way, I don't take search_text from $_GET, but using get_query_var. So the following alone worked for me: urldecode( get_query_var('search_text') ) ; – HOY Aug 9 '17 at 23:08
  • 1
    I didn't have access to your code, so that was a total guess. Glad to see you've found the cure for the problem :) – Jack Johansson Aug 9 '17 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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