Custom Post Type

These routes allow you to get/create/update/delete entries or a single entry of a custom post type.

Any new post type registered through register_post_type() gets a basic route handler WP_REST_Posts_Controller{}. See the parameter rest_controller_class.

This means that when registering a post type, if the parameter rest_controller_class is not set, we automatically get routes that are completely analogous to the routes for posts, only in the route path instead of posts you need to use the name of our post type:

/wp/v2/my_post_type       // works with entries of type my_post_type
/wp/v2/my_post_type/{ID}  // works with the entry with ID = {ID}

Otherwise, these routes are used exactly the same as post routes.

To make the route work when registering a post type, you need to specify show_in_rest = true!

my_post_type in the route /wp/v2/my_post_type is the parameter rest_base that is specified when registering the post type. By default = the post type slug.