Ask any question about WordPress here... and get an instant response.
How can I create a custom post type with its own custom fields?
Asked on Oct 28, 2025
Answer
Creating a custom post type with its own custom fields in WordPress involves registering the post type and defining the fields you want to associate with it. This can be done through code in your theme's `functions.php` file or via a plugin.
<!-- BEGIN COPY / PASTE -->
// Register Custom Post Type
function create_custom_post_type() {
$labels = array(
'name' => _x('Books', 'Post Type General Name', 'text_domain'),
'singular_name' => _x('Book', 'Post Type Singular Name', 'text_domain'),
'menu_name' => __('Books', 'text_domain'),
);
$args = array(
'label' => __('Book', 'text_domain'),
'supports' => array('title', 'editor', 'custom-fields'),
'public' => true,
'has_archive' => true,
);
register_post_type('book', $args);
}
add_action('init', 'create_custom_post_type', 0);
<!-- END COPY / PASTE -->Additional Comment:
- To add custom fields, you can use the built-in "custom-fields" support or a plugin like Advanced Custom Fields (ACF) for more flexibility.
- Ensure that the custom post type slug ('book' in this example) is unique and not conflicting with any existing post types or taxonomies.
- Custom fields can be displayed in your theme using `get_post_meta()` function.
- Remember to flush the rewrite rules by visiting the Permalinks settings page after registering a new post type.
Recommended Links:
