Skip to content

Instantly share code, notes, and snippets.

View gerbenvandijk's full-sized avatar

Gerben van Dijk gerbenvandijk

  • Tech Lead Frontend @ Foodticket
  • Amsterdam, The Netherlands
View GitHub Profile
mvaessen / WP REST-API search all (specified) post-types
Last active August 4, 2016 08:16
In order to search all post-types using the WP REST-API, which is not possible with the API, you can use this piece of code to search for all specified post-types. Replace all the 'POSTTYPE' parts with your CPT's slug, and it will be searchable in 1 query. You can also add additional CPT's. Using the ?embedded=true, you get all the embedded data!
add_action('rest_api_init', function () {
register_rest_route('mvaessen/v1', '/search', array(
'methods' => 'GET',
'callback' => 'search_all_endpoint',
function search_all_endpoint(WP_REST_Request $request)