Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with REST API support in WordPress?
Asked on Jan 07, 2026
Answer
To create a custom post type in WordPress with REST API support, you need to register the post type using the `register_post_type` function and ensure the `show_in_rest` parameter is set to `true`. This will make your custom post type accessible via the WordPress REST API.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'show_in_rest' => true, // Enable REST API support
'supports' => array('title', 'editor', 'thumbnail'),
);
register_post_type('book', $args);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you place this code in your theme's `functions.php` file or in a custom plugin.
- Replace 'Books' and 'book' with your desired labels and slug.
- After registering, your custom post type will be available at `/wp-json/wp/v2/book`.
- Use the REST API to interact with your custom post type programmatically.
Recommended Links:
