Search Posts

Advertisement

To search for posts using the WordPress REST API, you can use the GET method and pass the search parameter with your query as the value.

For example:

GET /wp-json/wp/v2/posts?search=biography

This will return an array of posts that match your search query biography

If you have any page, post or custom post type then you’ll get all of them in the response.

You can also pass other parameters to filter or sort the results, such as author, categories, tags, and orderby.

Here is an example of a more complex search query that searches for posts with the keyword “WordPress” in the title or content, and filters the results to only include posts by the author with an ID of 1, sorted by the date they were published in descending order:

GET /wp-json/wp/v2/posts?search=WordPress&author=1&orderby=date&order=desc

Keep in mind that the WordPress REST API has a default limit of 10 posts per page, so if you want to retrieve more than 10 results, you will need to use the page parameter to paginate through the results.

For example:

GET /wp-json/wp/v2/posts?search=WordPress&author=1&orderby=date&order=desc&page=2

This will retrieve the second page of results. You can also use the per_page parameter to change the number of results per page.

I hope this helps! Let me know if you have any other questions.

Leave a Reply