Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress REST API Global Search (API V2)

I am looking for a way to run a global search query across all or multiple post types using WP REST API.

I am able to search posts using:

http://example.com/wp-json/wp/v2/posts?search=test

In turn I am able to search pages using:

http://example.com/wp-json/wp/v2/pages?search=test

How do I search across both posts and pages? I was able to do this in WP REST API V1 by specifying multiple type[] variables in the query?

like image 847
Marc Avatar asked Jun 28 '16 19:06

Marc


1 Answers

This might be a bit late but there is an endpoint for that in the v2-api: /wp-json/wp/v2/search.

You can search for any specific post_type by supplying it via subtype or leave it to the default (any) to search in all post_types.

 

Edit: Of course you can also specifiy multiple with an array as you did before.

like image 88
Consti P Avatar answered Oct 21 '22 21:10

Consti P