Adding A Custom Post Type With REST Support

This is effectively very trivial but not obvious, one those who wants to be a millionaire ‘its easy of you know the answer’ ones. So lets add a Custom Post Type.

When you create the custom post type you need to add this to the arguments of the register_post_type function:

'show_in_rest' => true,

Here is a complete code example with the required element on line 29

Once you have done this and added some entries to your custom post type you can use the slug of the post type as an end point to the api so you have in our development example http://bbtutorial.dev/wp-json/wp/v2/blog_entry

This returns a response in Postman of:

REST cpt
REST API Call to a Custom Post Type

Leave a Reply