0

I'm working with wordpress rest api I need to searching WP posts with unicode character example searching on my site:

https://example.net/?s=ngoại+tình

The results is OK The I applied to my api : API URL :

https://example.net/wp-json/v1/search?keyword=ngoại+tình

Code:

$arrayPostFilter = array (
        "orderby" => "publish_date",
        "s" => $_GET['keyword'], 
        "posts_per_page" => 20,     
        'numberposts'=>-1,
        "paged" => $paged
    );

It's have no result, no posts found

Do I have to setting anything relate to Unicode for query filter?

  • 1
    Is there any specific reasons you're still using the old REST API version? And with version 2, you'd simply make requests to /wp-json/wp/v2/posts?search=keyword, but remove the "s" => $_GET['keyword'] in your code. – Sally CJ Dec 23 '18 at 5:06
  • v1/search is my custom api. The problem is that I can not search with keyword unicode – Ryo Dec 24 '18 at 1:32
  • Yes, I did think of that. So try using sanitize_text_field( $_GET['keyword'] ) ? – Sally CJ Dec 24 '18 at 1:45
  • Oh, you save my day. It's work with sanitize_text_field. Thank you very much @SallyCJ – Ryo Dec 24 '18 at 4:09
  • You're welcome & merry Christmas! – Sally CJ Dec 24 '18 at 22:12

Your Answer

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

Browse other questions tagged or ask your own question.