Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with specific REST API endpoints in WordPress?
Asked on Jan 25, 2026
Answer
Creating a custom post type in WordPress with specific REST API endpoints involves registering the post type and configuring its REST API settings. This process is done through your theme's `functions.php` file or a custom plugin.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$args = array(
'label' => 'Books',
'public' => true,
'show_in_rest' => true, // Enables REST API support
'rest_base' => 'books', // Custom REST API base endpoint
'supports' => array('title', 'editor', 'thumbnail'),
);
register_post_type('book', $args);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- The 'show_in_rest' parameter must be set to true to enable REST API support for the custom post type.
- The 'rest_base' parameter allows you to define a custom endpoint for your post type in the REST API.
- Ensure your theme or plugin is active to register the custom post type properly.
- Use the REST API endpoint "/wp-json/wp/v2/books" to interact with the custom post type.
Recommended Links:
