3

Having browsed the official WordPress REST API site - and looking at the various endpoints - I cannot find information of custom post types. I appreciate there is the WordPress REST API Plugin that appears to add support for CPT's - but does the official API support them?

If not - is there a reason for this?

  • you will have to define "official" – Mark Kaplun Oct 14 '16 at 13:51
  • what about this? – Lucio Crusca Oct 14 '16 at 13:53
  • I think what you are looking for is here v2.wp-api.org/extending/custom-content-types – stims Oct 14 '16 at 14:14
  • sorry guys, links hadn't worked - official as far as I can tell is the first link – DJC Oct 14 '16 at 14:27
  • @stims - thanks but I've already mentioned that in my question - I'm not asking about the plugin – DJC Oct 14 '16 at 15:44
4

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!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.