About

With Custom Post Types, you can extend the WordPress back-end by allowing for the storage and manipulation of 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' => _x( 'Books', 'book' ),
    'singular_name' => _x( 'Book', 'book' ),
    'add_new' => _x( 'Add New', 'book' ),
    'add_new_item' => _x( 'Add New Book', 'book' ),
    'edit_item' => _x( 'Edit Book', 'book' ),
    'new_item' => _x( 'New Book', 'book' ),
    'view_item' => _x( 'View Book', 'book' ),
    'search_items' => _x( 'Search Books', 'book' ),
    'not_found' => _x( 'No books found', 'book' ),
    'not_found_in_trash' => _x( 'No books found in Trash', 'book' ),
    'parent_item_colon' => _x( 'Parent Book:', 'book' ),
    'menu_name' => _x( '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'
);
history | show excerpt | excerpt history