The WordPress.com REST API has always enabled developers to manage categories and tags for the posts on a site. Until now, however, if a site had enabled any custom post types with custom taxonomies, developers were out of luck if they had hoped to manage custom terms using the REST API.
We’re happy to announce that this is no longer the case, with improved support for custom taxonomies. This includes a handful of new endpoints and enhancements to existing endpoints.
Specifically, you can now…
- Retrieve a list of terms for a site
- Retrieve a single term for a site
- Create a new term
- Update an existing term
- Delete a term
- List taxonomies associated with a post type
- Retrieve a post including terms for all public taxonomies
- Create or update a post including terms for any taxonomy
- List posts filtered by a custom taxonomy term (available now for WordPress.com sites and in a future Jetpack release)
Note that taxonomies and terms are only included in a response if the taxonomy is registered as public or if the authorization token sent with the request has the proper capabilities for viewing or managing that taxonomy. Refer to the
register_taxonomy function documentation for more information.
As an example, if a Jetpack site supported a custom book post type with a genre taxonomy, I could create a new book by issuing the following cURL command:
curl \ -H 'authorization: Bearer YOUR_API_TOKEN' \ --data-urlencode 'title=Sample Book' \ --data-urlencode 'type=book' \ --data-urlencode 'terms[genre]=Fiction' \ 'https://public-api.wordpress.com/rest/v1.2/sites/example.com/posts/new/'
If you’re new to working with the WordPress.com REST API, we recommend you head on over to our Getting Started with the API guide to learn more.