Does the REST API (official) support custom post types?

Thanks for the clarification in the comments. The confusion is between the WordPress.com hosted API and the WordPress.org REST API project, which are different. The WordPress.com API was developed by Automattic and is only available for websites hosted on the WordPress.com platform. There’s some overlap in functionality, but that’s not the documentation you’re looking for if you’re building a site with the downloadable version of WordPress from WordPress.org.

The official documentation for the REST API plugin that works with downloadable WordPress is here. Parts of the plugin have already been integrated into WordPress core, and it looks like the another big chunk is on track to be merged in an upcoming WordPress release, probably 4.8 or 4.9.

To answer your question about whether the API supports custom post types, it definitely does! When you’re registering your custom post type with the register_post_type function, add the following argument:

'show_in_rest' => true

That’s the minimumum amount of code, which makes your post type part of the public API. You can do things like add custom namespaces and authentication functions, but that’s not necessary if your API is public and you’re just getting started.

To answer your follow-up question about using the API with Angular – yes, the WP-Admin dashboards all work exactly the same when the API is enabled, you can edit using the dashboard and use the API as a read-only client.

Good luck with your project and have fun!

Leave a Comment