The WordPress’s register post type() function can be used to establish a custom post type. An illustration of how to construct a custom post type called “Books” is shown below:

PHP Code:
<?php
function create_book_post_type() {
register_post_type('book',
array(
'labels' => array(
'name' => __('Books'),
'singular_name' => __('Book')
),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
add_action('init', 'create_book_post_type');
?>

This code creates a new custom post type called “Book” and sets its properties, including the labels for the post type and its various states, whether it should be publicly accessible, whether it should have an archive, and which post fields it should support.

Once you’ve added this code to your theme’s functions.php file or a custom plugin, you’ll be able to access your new custom post type by visiting the Posts > Books section in the WordPress admin area.

Pin It on Pinterest