I am writing Android application and I am using WordPress REST API v2 for communication with WordPress from my Android application. I have implemented Activity that lists all posts from single category:
http://wordpress.dev/wp-json/wp/v2/posts?categories=X
But now I am adding search box in my application where user can enter some text and now I need to use this text to perform search over all categories
I can use same endpoint but different parameters:
http://wordpress.dev/wp-json/wp/v2/posts?search=<SEARCH TEXT>
In my local wordpress database I have a lot of posts that are called "POST TITLE #XY" and one that is called "Cover Photo"
So if I execute this:
http://wordpress.dev/wp-json/wp/v2/posts?search=title,post
I get only those that has post and title in the title, however if I add one more word:
http://wordpress.dev/wp-json/wp/v2/posts?search=title,post,cover
I get zero posts...
How can I perform search and get posts that includes one or more keywords that I am sending in request?
You can use Search Results REST API Endpoint to seach by keywords you provide.
For example http://yourdomain.com/index.php/wp-json/wp/v2/search?search=lorem&per_page=5&page=1
will search for the keyword lorem
in your wordpress posts.
Per_page : limits the number of results per page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With