Reputation: 1635
According to the WP rest API handbook, I dont see an argument for post type when creating a post using the API. Is there a different way to do this?
Upvotes: 0
Views: 4287
Reputation: 5127
http://yourwebsite.com/wp-json contains all the details of the restapi. You can explore there or take it as a text file and you can explore there.
Take a curl -Lk https://www.yourwebsite.com/ wp-json > wp-json-output.json
and explore this file.
Upvotes: 0
Reputation: 11
Yeah, when you create a custom post type, the endpoint at the URL will be the custom post type slug. For instance, if you created a CPT named travels
, you can reach your API response from [your-url-site-here]/wp/v2/travels
. Then you can insert, get or delete whatever you want.
Upvotes: 1
Reputation: 1635
I figured out if you add 'show_in_rest' => true when you define the custom post type, that it will essentially create a post type end point. So if your post type is books, it'll create url.com/wp-json/wp-vs/books.
Upvotes: 1
Reputation:
The post type is part of the endpoint URL - i.e. not a query parameter. For the built in post types post, page and attachment the endpoints are:
http://www.example.com/wp-json/wp/v2/posts
http://www.example.com/wp-json/wp/v2/pages
http://www.example.com/wp-json/wp/v2/media
Each post type has its own endpoint and its own WP_REST_Controller which is specified in the call to register_post_type() by the parameter 'rest_controller_class'. The parameter 'rest_base' specifies the last part of the endpoint path. Note that for post type = 'attachment' the endpoint is 'media' so the endpoint label may not be derived from the post type but is just what is specified by the 'rest_base' parameter in the call to register_post_type().
Upvotes: 5