Make WordPress Core

#46761 closed defect (bug) (invalid)

Argument missing from 'register_post_type' codex docs

Reported by: leec87 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:


There is a label missing from the elaborate example of registering a new post type.

'view_items' is not present, and is used when archive is enabled, and the link in the admin menu bar is shown. By default, this shows 'View Posts' to open the archive page from wp-admin.

This label will rename this to suit your post type, and should be included between 'view_item' and 'all_items'.


add_action( 'init', 'codex_book_init' );
 * Register a book post type.
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
function codex_book_init() {
        $labels = array(
                'name'               => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
                'singular_name'      => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
                'menu_name'          => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
                'name_admin_bar'     => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
                'add_new'            => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
                'add_new_item'       => __( 'Add New Book', 'your-plugin-textdomain' ),
                'new_item'           => __( 'New Book', 'your-plugin-textdomain' ),
                'edit_item'          => __( 'Edit Book', 'your-plugin-textdomain' ),
                'view_item'          => __( 'View Book', 'your-plugin-textdomain' ),
// INSERT ->    'view_items'         => __( 'View Books', 'your-plugin-textdomain' ),
                'all_items'          => __( 'All Books', 'your-plugin-textdomain' ),
                'search_items'       => __( 'Search Books', 'your-plugin-textdomain' ),
                'parent_item_colon'  => __( 'Parent Books:', 'your-plugin-textdomain' ),
                'not_found'          => __( 'No books found.', 'your-plugin-textdomain' ),
                'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )

        $args = array(
                'labels'             => $labels,
                'description'        => __( 'Description.', 'your-plugin-textdomain' ),
                'public'             => true,
                'publicly_queryable' => true,
                'show_ui'            => true,
                'show_in_menu'       => true,
                'query_var'          => true,
                'rewrite'            => array( 'slug' => 'book' ),
                'capability_type'    => 'post',
                'has_archive'        => true,
                'hierarchical'       => false,
                'menu_position'      => null,
                'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )

        register_post_type( 'book', $args );

Change History (1)

#1 @swissspidy
22 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

That "elaborate" example is missing much more labels than just view_items :-) I'd say it's easier to just point to the docs instead of listing all possible labels there.

The good thing is: the codex is a wiki, which anyone can edit! So if you see an issue like this that you think is worth fixing, you can just log in with your WordPress.org username and edit the page.

That being said, the source of truth for documentation is https://developer.wordpress.org/reference as we're slowly moving away from Codex.

The relevant documentation for register_post_type() explicitly says this about the labels:

An array of labels for this post type. If not set, post labels are inherited for non-hierarchical types and page labels for hierarchical ones. See get_post_type_labels() for a full list of supported labels.

See https://developer.wordpress.org/reference/functions/get_post_type_labels/ for the full list of labels.

Note: See TracTickets for help on using tickets.