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?

Solutions

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.

Similar questions

How to define Wordpress global variable for use in a REST Controller?
I'm extending the WP REST API by writing a Controller class. I'm trying to read the config for this class from a file, e.g: This would allow me to keep server and client in sync as they would both use the same config file. However, I do not want WP to stay reading this file for every request it serves... Currently, if I read this file from anywhere...
How to create a new rest url prefix in Wordpress REST API?
I'd like to have in my website two url prefixes to reach two different api base paths, in particular: I need to keep wp-json url prefix I need to create a new prefix called api, so I can create new routes and endpoints there. I've found this method but it hides also wp-json, while I'd need to create a new url prefix, different from it but working c...
PHP Fatal error: Cannot use object of type WP_REST_Response as array in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
I've added a custom endpoint to WordPress like so: Which cherry picks posts based on the intersection of a category and terms from a particular custom taxonomy. In my local development environment this returns the posts I expect or the 404 response where it should. On the production it returns a 500 http error and the error log reports a PHP Fatal ...
Register rest field authentication with REST API
I'm trying to add some user meta information to the existing wp/v2/users REST endpoint. However, it looks like additional authentication is required, i.e. I get this (output in comments): (so it doesn't seem possible to get actual user meta in the new field I registered). Firstly: please correct me if I'm wrong on this point because it would make t...
is it possible to filter a rest api endpoint by using a registered rest field?
I added a rest field into a custom post type endpoint as following: Now I would like to order by artists, is this possible?
Conflict between the search function and the global $post object when trying to add a filter to add a class in the body in WordPress
Here's my problem. I want to add a class to the body tag of a post or page if the post/page is a child of another post. So far so good: And it works like a charm but when I use the search function within WordPress (when I try to return all the post or page base on a word), the system still works but it throws this error: Notice: Trying to get prope...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .