Create a Post Type
Last updated
Last updated
You can use PostTypes to create a new post type, or work with an . PostTypes can be included in your theme or plugins.
To create a new post type pass the post types name to the class constructor. In order to apply changes to WordPress you must call the register()
method.
The post type labels and slugs are automatically generated from the post type name, however, you can set these manually by passing an array of names to the class constructor.
The following names are accepted.
Key
Description
Example
name
is the post type name
required, singular, lowercase, underscores
singular
is the singular label for the post type
e.g 'Book', 'Person'
plural
is the plural label for the post type
e.g 'Books', 'People'
slug
is the post type slug used in the permalinks
plural, lowercase, hyphens
The only required field is the post type's name
, all others are optional.
Options for the post type are set by passing an array as the second argument in the class constructor.
Alternatively, you can set options using the options()
method.
You can set the labels for the post type by passing an array as the third argument in the class constructor.
Alternatively, you can use the labels()
method to set the labels for the post type.
To work with existing post types pass the post type name into the constructor. Be careful and avoid using global variables (e.g $post
) which can lead to unwanted results.
The options match the arguments passed to the register_post_type()
WordPress function. All available options are on the
All available labels are on the