It is not possible to query multiple post types simultaneously using the getEntityRecords()
selector. This is because the WordPress REST API is not built around the same ideology as the core WordPress back-end.
All data-types being “posts” in the traditional PHP APIs is the product of the somewhat controversial underlying database implementation, while the REST API was built to be insulated from the database implementation, and treats each post type as it’s own “resource” in isolation for the most part.
In your case, searching the relevant record-types individually is probably the best solution. If you really do wish to search all post types which are exposed over the REST API, you can use the getPostTypes()
selector from the core
data store in order to retrieve a list of types.
Alternatively, the REST API does expose a search
endpoint. While not presently very clearly documented in the REST API Handbook, this endpoint’s subtype
parameter does accept an array of post types. This could be queried using the @wordpress/api-fetch
package, but it’s worth noting that the functionality and caching would not automatically leverage Gutenberg’s data stores – it may be necessary to implement a custom data-store to most efficiently implement your search functionality (prevent identical repeated requests to the REST API per render, automatically trigger re-renders for selected data, etc.).