Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with custom fields in WordPress?
Asked on Feb 28, 2026
Answer
Creating a custom post type with custom fields in WordPress allows you to organize and display different types of content beyond the default posts and pages. This can be achieved through code or plugins.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
register_post_type('book',
array(
'labels' => array(
'name' => __('Books'),
'singular_name' => __('Book')
),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'custom-fields'),
)
);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Custom fields can be added using the "custom-fields" support in the 'supports' array, or by using plugins like Advanced Custom Fields (ACF) for more complex field management.
- Ensure your theme supports the custom post type by modifying template files if necessary.
- Remember to flush rewrite rules after registering a new post type by visiting the Permalinks settings page.
Recommended Links:
