Custom Post Types extend WordPress to support additional content.
With Custom Post Types, you can extend WordPress by allowing for the storage and manipulation of both post and non-post content.
Example - Books
Instead of writing a post about a book and flagging it with a category, you can create a separate post type called "Books." This post type will have its own menu item in the admin menu, and can have its own sets of categories and tags.
Custom Post Types also support custom meta fields for storing additional information. In the case of a book, you can store author names, publisher information, publication data, and cover graphics.
Since Custom Post Types are distinct from posts and pages, they can be queried independently and will not clutter the regular loop on a blog-style homepage.
A short and simple way to add a Books custom post type:
add_action( 'init', 'register_cpt_books' );
function register_cpt_books() {
register_post_type( 'books',
array(
'labels' => array(
'name' => __( 'Books' ),
'singular_name' => __( 'Books' )
),
'public' => true,
'has_archive' => true,
)
);
}
Alternatively, custom post types can be registered with several labeling options, support for custom taxonomies, and with various visibility and accessibility options.
add_action( 'init', 'register_cpt_book' );
function register_cpt_book() {
$labels = array(
'name' => __( 'Books', 'book' ),
'singular_name' => __( 'Book', 'book' ),
'add_new' => __( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Book', 'book' ),
'edit_item' => __( 'Edit Book', 'book' ),
'new_item' => __( 'New Book', 'book' ),
'view_item' => __( 'View Book', 'book' ),
'search_items' => __( 'Search Books', 'book' ),
'not_found' => __( 'No books found', 'book' ),
'not_found_in_trash' => __( 'No books found in Trash', 'book' ),
'parent_item_colon' => __( 'Parent Book:', 'book' ),
'menu_name' => __( 'Books', 'book' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'A list of posts about books.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'comments', 'revisions' ),
'taxonomies' => array( 'category', 'post_tag', 'books' ), // Register the Book custom post type to use the "books" custom taxonomy
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
}
Reference from WordPress Codex: Custom Post Types