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...
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...
Also ask