Languages:
English •
中文(简体) •
日本語
(Add your language)
Description
Create or modify a post type. register_post_type should only be invoked through the 'init' action. It will not work if called before 'init', and aspects of the newly created or modified post type will work incorrectly if called later.
Note: You can use this function in themes and plugins. However, if you use it in a theme, your post type will disappear from the admin if a user switches away from your theme. See Must Use Plugins If you want to keep your changes e.g. post type, even if you switch between your themes.
Taxonomies
When registering a post type, always register your taxonomies using the taxonomies
argument. If you do not, the taxonomies and post type will not be recognized as connected when using filters such as parse_query
or pre_get_posts
. This can lead to unexpected results and failures.
Even if you register a taxonomy while creating the post type, you must still explicitly register and define the taxonomy using register_taxonomy().
Reserved Post Types
The following post types are reserved and used by WordPress already.
- post
- page
- attachment
- revision
- nav_menu_item
- custom_css
- customize_changeset
- oembed_cache
- user_request
- wp_block
In addition, the following post types should not be used as they interfere with other WordPress functions.
- action
- author
- order
- theme
In general, you should always prefix your post types, or specify a custom `query_var`, to avoid conflicting with existing WordPress query variables.
More information: Post Types.
Usage
<?php register_post_type( $post_type, $args ); ?>
Parameters
- $post_type
- (string) (required) Post type. (max. 20 characters, cannot contain capital letters, underscores or spaces)
- Default: None
- $args
- (array) (optional) An array of arguments.
- Default: None
Arguments
- label
- (string) (optional) A plural descriptive name for the post type marked for translation.
- Default: Value of $labels['name']
- labels
- (array) (optional) labels - An array of labels for this post type. By default, post labels are used for non-hierarchical post types and page labels for hierarchical ones.
- Default: if empty, 'name' is set to value of 'label', and 'singular_name' is set to value of 'name'.
- 'name' - general name for the post type, usually plural. The same and overridden by $post_type_object->label. Default is Posts/Pages
- 'singular_name' - name for one object of this post type. Default is Post/Page
- 'add_new' - the add new text. The default is "Add New" for both hierarchical and non-hierarchical post types. When internationalizing this string, please use a gettext context matching your post type. Example:
_x('Add New', 'product');
- 'add_new_item' - Default is Add New Post/Add New Page.
- 'edit_item' - Default is Edit Post/Edit Page.
- 'new_item' - Default is New Post/New Page.
- 'view_item' - Default is View Post/View Page.
- 'view_items' - Label for viewing post type archives. Default is 'View Posts' / 'View Pages'.
- 'search_items' - Default is Search Posts/Search Pages.
- 'not_found' - Default is No posts found/No pages found.
- 'not_found_in_trash' - Default is No posts found in Trash/No pages found in Trash.
- 'parent_item_colon' - This string isn't used on non-hierarchical types. In hierarchical ones the default is 'Parent Page:'.
- 'all_items' - String for the submenu. Default is All Posts/All Pages.
- 'archives' - String for use with archives in nav menus. Default is Post Archives/Page Archives.
- 'attributes' - Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'.
- 'insert_into_item' - String for the media frame button. Default is Insert into post/Insert into page.
- 'uploaded_to_this_item' - String for the media frame filter. Default is Uploaded to this post/Uploaded to this page.
- 'featured_image' - Default is Featured Image.
- 'set_featured_image' - Default is Set featured image.
- 'remove_featured_image' - Default is Remove featured image.
- 'use_featured_image' - Default is Use as featured image.
- 'menu_name' - Default is the same as `name`.
- 'filter_items_list' - String for the table views hidden heading.
- 'items_list_navigation' - String for the table pagination hidden heading.
- 'items_list' - String for the table hidden heading.
- 'name_admin_bar' - String for use in New in Admin menu bar. Default is the same as `singular_name`.
There are five additional labels have been made available for custom post types since wordpress 5.0
- 'item_published' - The label used in the editor notice after publishing a post. Default “Post published.” / “Page published.”
- 'item_published_privately' - The label used in the editor notice after publishing a private post. Default “Post published privately.” / “Page published privately.”
- 'item_reverted_to_draft' - The label used in the editor notice after reverting a post to draft. Default “Post reverted to draft.” / “Page reverted to draft.”
- 'item_scheduled' - The label used in the editor notice after scheduling a post to be published at a later date. Default “Post scheduled.” / “Page scheduled.”
- 'item_updated' - The label used in the editor notice after updating a post. Default “Post updated.” / “Page updated.”
Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages).
- description
- (string) (optional) A short descriptive summary of what the post type is.
- Default: blank
The only way to read that field is using this code:
$obj = get_post_type_object( 'your_post_type_name' );
echo esc_html( $obj->description );
- public
- (boolean) (optional) Controls how the type is visible to authors (
show_in_nav_menus
, show_ui
) and readers (exclude_from_search
, publicly_queryable
).
- Default: false
- 'true' - Implies
exclude_from_search: false
, publicly_queryable: true
, show_in_nav_menus: true
, and show_ui:true
. The built-in types attachment, page, and post are similar to this.
- 'false' - Implies
exclude_from_search: true
, publicly_queryable: false
, show_in_nav_menus: false
, and show_ui: false
. The built-in types nav_menu_item and revision are similar to this. Best used if you'll provide your own editing and viewing interfaces (or none at all).
- If no value is specified for
exclude_from_search
, publicly_queryable
, show_in_nav_menus
, or show_ui
, they inherit their values from public
.
- exclude_from_search
- (boolean) (importance) Whether to exclude posts with this post type from front end search results.
- Default: value of the opposite of public argument
- 'true' - site/?s=search-term will not include posts of this post type.
- 'false' - site/?s=search-term will include posts of this post type.
- Note: If you want to show the posts's list that are associated to taxonomy's terms, you must set exclude_from_search to false (ie : for call site_domaine/?taxonomy_slug=term_slug or site_domaine/taxonomy_slug/term_slug). If you set to true, on the taxonomy page (ex: taxonomy.php) WordPress will not find your posts and/or pagination will make 404 error...
- publicly_queryable
- (boolean) (optional) Whether queries can be performed on the front end as part of parse_request().
- Default: value of public argument
- Note: The queries affected include the following (also initiated when rewrites are handled)
- ?post_type={post_type_key}
- ?{post_type_key}={single_post_slug}
- ?{post_type_query_var}={single_post_slug}
- Note: If query_var is empty, null, or a boolean FALSE, WordPress will still attempt to interpret it (4.2.2) and previews/views of your custom post will return 404s.
- show_ui
- (boolean) (optional) Whether to generate a default UI for managing this post type in the admin.
- Default: value of public argument
- 'false' - do not display a user-interface for this post type
- 'true' - display a user-interface (admin panel) for this post type
- Note: _built-in post types, such as post and page, are intentionally set to false.
- show_in_admin_bar
- (boolean) (optional) Whether to make this post type available in the WordPress admin bar.
- Default: value of the show_in_menu argument
- capability_type
- (string or array) (optional) The string to use to build the read, edit, and delete capabilities. May be passed as an array to allow for alternative plurals when using this argument as a base to construct the capabilities, e.g. array('story', 'stories') the first array element will be used for the singular capabilities and the second array element for the plural capabilities, this is instead of the auto generated version if no array is given which would be "storys". The 'capability_type' parameter is used as a base to construct capabilities unless they are explicitly set with the 'capabilities' parameter. It seems that `map_meta_cap` needs to be set to false or null, to make this work (see note 2 below).
- Default: "post"
- Example with "book" or "array( 'book', 'books' )" value, it's generate the 7 capabilities equal to set capabilities parameter to this :
'capabilities' => array(
'edit_post' => 'edit_book',
'read_post' => 'read_book',
'delete_post' => 'delete_book',
'edit_posts' => 'edit_books',
'edit_others_posts' => 'edit_others_books',
'publish_posts' => 'publish_books',
'read_private_posts' => 'read_private_books',
'create_posts' => 'edit_books',
),
- Note 1: The "create_posts" capability correspond to "edit_books" so it become equal to "edit_posts".
- Note 2: See capabilities note 2 about meta capabilities mapping for custom post type.
- You can take a look into the $GLOBALS['wp_post_types']['your_cpt_name'] array, then you'll see the following:
[cap] => stdClass Object
(
// Meta capabilities
[edit_post] => edit_book
[read_post] => read_book
[delete_post] => delete_book
// Primitive capabilities used outside of map_meta_cap():
[edit_posts] => edit_books
[edit_others_posts] => edit_others_books
[publish_posts] => publish_books
[read_private_posts] => read_private_books
// Primitive capabilities used within map_meta_cap():
[create_posts] => edit_books
)
- Some of the capability types that can be used (probably not exhaustive list):
- These built-in types cannot be used:
- Note 3: If you use capabilities parameter, capability_type complete your capabilities.
- capabilities
- (array) (optional) An array of the capabilities for this post type.
- Default: capability_type is used to construct
- By default, seven keys are accepted as part of the capabilities array:
- edit_post, read_post, and delete_post - These three are meta capabilities, which are then generally mapped to corresponding primitive capabilities depending on the context, for example the post being edited/read/deleted and the user or role being checked. Thus these capabilities would generally not be granted directly to users or roles.
- edit_posts - Controls whether objects of this post type can be edited.
- edit_others_posts - Controls whether objects of this type owned by other users can be edited. If the post type does not support an author, then this will behave like edit_posts.
- publish_posts - Controls publishing objects of this post type.
- read_private_posts - Controls whether private objects can be read.
- Note 1: those last four primitive capabilities are checked in core in various locations.
- There are also eight other primitive capabilities which are not referenced directly in core, except in map_meta_cap(), which takes the three aforementioned meta capabilities and translates them into one or more primitive capabilities that must then be checked against the user or role, depending on the context. These additional capabilities are only used in map_meta_cap(). Thus, they are only assigned by default if the post type is registered with the 'map_meta_cap' argument set to true (default is false).
- read - Controls whether objects of this post type can be read.
- delete_posts - Controls whether objects of this post type can be deleted.
- delete_private_posts - Controls whether private objects can be deleted.
- delete_published_posts - Controls whether published objects can be deleted.
- delete_others_posts - Controls whether objects owned by other users can be can be deleted. If the post type does not support an author, then this will behave like delete_posts.
- edit_private_posts - Controls whether private objects can be edited.
- edit_published_posts - Controls whether published objects can be edited.
- create_posts - Controls whether new objects can be created
- Note 2: In fact, when some user have a role with just the post type capabilies it isn't enough for create new object... It's because meta capabilities for custom post types were not being automatically mapped, so we couldn’t have granular control over permissions. To map meta capabilities for custom post types we can use map_meta_cap hook as it's explain here : http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types.
If you assign a 'capability_type' and then take a look into the $GLOBALS['wp_post_types']['your_cpt_name'] array, then you'll see the following:
[cap] => stdClass Object
(
// Meta capabilities
[edit_post] => "edit_{$capability_type}"
[read_post] => "read_{$capability_type}"
[delete_post] => "delete_{$capability_type}"
// Primitive capabilities used outside of map_meta_cap():
[edit_posts] => "edit_{$capability_type}s"
[edit_others_posts] => "edit_others_{$capability_type}s"
[publish_posts] => "publish_{$capability_type}s"
[read_private_posts] => "read_private_{$capability_type}s"
// Primitive capabilities used within map_meta_cap():
[read] => "read",
[delete_posts] => "delete_{$capability_type}s"
[delete_private_posts] => "delete_private_{$capability_type}s"
[delete_published_posts] => "delete_published_{$capability_type}s"
[delete_others_posts] => "delete_others_{$capability_type}s"
[edit_private_posts] => "edit_private_{$capability_type}s"
[edit_published_posts] => "edit_published_{$capability_type}s"
[create_posts] => "edit_{$capability_type}s"
)
Note the "s" at the end of plural capabilities.
- hierarchical
- (boolean) (optional) Whether the post type is hierarchical (e.g. page). Allows Parent to be specified. The 'supports' parameter should contain 'page-attributes' to show the parent select box on the editor page.
- Default: false
- Note: this parameter was intended for Pages. Be careful when choosing it for your custom post type - if you are planning to have very many entries (say - over 2-3 thousand), you will run into load time issues. With this parameter set to true WordPress will fetch all IDs of that particular post type on each administration page load for your post type. Servers with limited memory resources may also be challenged by this parameter being set to true.
- supports
- (array/boolean) (optional) An alias for calling add_post_type_support() directly. As of 3.5, boolean false can be passed as value instead of an array to prevent default (title and editor) behavior.
- Default: title and editor
- 'title'
- 'editor' (content)
- 'author'
- 'thumbnail' (featured image, current theme must also support post-thumbnails)
- 'excerpt'
- 'trackbacks'
- 'custom-fields'
- 'comments' (also will see comment count balloon on edit screen)
- 'revisions' (will store revisions)
- 'page-attributes' (menu order, hierarchical must be true to show Parent option)
- 'post-formats' add post formats, see Post Formats
- Note: When you use custom post type that use thumbnails remember to check that the theme also supports thumbnails or use add_theme_support function.
- taxonomies
- (array) (optional) An array of registered taxonomies like
category
or post_tag
that will be used with this post type. This can be used in lieu of calling register_taxonomy_for_object_type() directly. Custom taxonomies still need to be registered with register_taxonomy().
- Default: no taxonomies
- has_archive
- (boolean or string) (optional) Enables post type archives. Will use $post_type as archive slug by default.
- Default: false
- Note: Will generate the proper rewrite rules if rewrite is enabled. Also use rewrite to change the slug used. If string, it should be translatable.
- rewrite
- (boolean or array) (optional) Triggers the handling of rewrites for this post type. To prevent rewrites, set to false.
- Default: true and use $post_type as slug
- $args array
- 'slug' => string Customize the permalink structure slug. Defaults to the $post_type value. Should be translatable.
- 'with_front' => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true
- 'feeds' => bool Should a feed permalink structure be built for this post type. Defaults to has_archive value.
- 'pages' => bool Should the permalink structure provide for pagination. Defaults to true
- 'ep_mask' => const As of 3.4 Assign an endpoint mask for this post type. For more info see Rewrite API/add_rewrite_endpoint, and Make WordPress Plugins summary of endpoints.
- If not specified, then it inherits from permalink_epmask(if permalink_epmask is set), otherwise defaults to EP_PERMALINK.
- Note: If registering a post type inside of a plugin, call flush_rewrite_rules() in your activation and deactivation hook (see Flushing Rewrite on Activation below). If flush_rewrite_rules() is not used, then you will have to manually go to Settings > Permalinks and refresh your permalink structure before your custom post type will show the correct structure.
- query_var
- (boolean or string) (optional) Sets the query_var key for this post type.
- Default: true - set to $post_type
- 'false' - Disables query_var key use. A post type cannot be loaded at /?{query_var}={single_post_slug}
- 'string' - /?{query_var_string}={single_post_slug} will work as intended.
- Note: The query_var parameter has no effect if the ‘publicly_queryable’ parameter is set to false. query_var adds the custom post type’s query var to the built-in query_vars array so that WordPress will recognize it. WordPress removes any query var not included in that array.
- If set to true it allows you to request a custom posts type (book) using this: example.com/?book=life-of-pi
- If set to a string rather than true (for example ‘publication’), you can do: example.com/?publication=life-of-pi
- can_export
- (boolean) (optional) Can this post_type be exported.
- Default: true
- delete_with_user
- (boolean) (optional) Whether to delete posts of this type when deleting a user. If true, posts of this type belonging to the user will be moved to trash when then user is deleted. If false, posts of this type belonging to the user will not be trashed or deleted. If not set (the default), posts are trashed if post_type_supports('author'). Otherwise posts are not trashed or deleted.
- Default: null
- show_in_rest
- (boolean) (optional) Whether to expose this post type in the REST API.
- Default: false
- rest_base
- (string) (optional) The base slug that this post type will use when accessed using the REST API.
- Default: $post_type
- rest_controller_class
- (string) (optional) An optional custom controller to use instead of WP_REST_Posts_Controller. Must be a subclass of WP_REST_Controller.
- Default: WP_REST_Posts_Controller
- _builtin
- (boolean) (not for general use) Whether this post type is a native or "built-in" post_type. Note: this Codex entry is for documentation - core developers recommend you don't use this when registering your own post type
- Default: false
- 'false' - default this is a custom post type
- 'true' - this is a built-in native post type (post, page, attachment, revision, nav_menu_item)
- _edit_link
- (boolean) (not for general use) Link to edit an entry with this post type. Note: this Codex entry is for documentation - core developers recommend you don't use this when registering your own post type
- Default:
Return Values
- (WP_Post_Type | WP_Error)
- The registered post type object, or an error object.
Example
An example of registering a post type called "book".
Basic:
function codex_custom_init() {
$args = array(
'public' => true,
'label' => 'Books'
);
register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );
Elaborate:
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' ),
'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 );
}
Customizing the messages:
add_filter( 'post_updated_messages', 'codex_book_updated_messages' );
/**
* Book update messages.
*
* See /wp-admin/edit-form-advanced.php
*
* @param array $messages Existing post update messages.
*
* @return array Amended post update messages with new CPT update messages.
*/
function codex_book_updated_messages( $messages ) {
$post = get_post();
$post_type = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );
$messages['book'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Book updated.', 'your-plugin-textdomain' ),
2 => __( 'Custom field updated.', 'your-plugin-textdomain' ),
3 => __( 'Custom field deleted.', 'your-plugin-textdomain' ),
4 => __( 'Book updated.', 'your-plugin-textdomain' ),
/* translators: %s: date and time of the revision */
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Book restored to revision from %s', 'your-plugin-textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __( 'Book published.', 'your-plugin-textdomain' ),
7 => __( 'Book saved.', 'your-plugin-textdomain' ),
8 => __( 'Book submitted.', 'your-plugin-textdomain' ),
9 => sprintf(
__( 'Book scheduled for: <strong>%1$s</strong>.', 'your-plugin-textdomain' ),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i', 'your-plugin-textdomain' ), strtotime( $post->post_date ) )
),
10 => __( 'Book draft updated.', 'your-plugin-textdomain' )
);
if ( $post_type_object->publicly_queryable && 'book' === $post_type ) {
$permalink = get_permalink( $post->ID );
$view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View book', 'your-plugin-textdomain' ) );
$messages[ $post_type ][1] .= $view_link;
$messages[ $post_type ][6] .= $view_link;
$messages[ $post_type ][9] .= $view_link;
$preview_permalink = add_query_arg( 'preview', 'true', $permalink );
$preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview book', 'your-plugin-textdomain' ) );
$messages[ $post_type ][8] .= $preview_link;
$messages[ $post_type ][10] .= $preview_link;
}
return $messages;
}
Adding contextual help:
//display contextual help for Books
function codex_add_help_text( $contextual_help, $screen_id, $screen ) {
//$contextual_help .= var_dump( $screen ); // use this to help determine $screen->id
if ( 'book' == $screen->id ) {
$contextual_help =
'<p>' . __('Things to remember when adding or editing a book:', 'your_text_domain') . '</p>' .
'<ul>' .
'<li>' . __('Specify the correct genre such as Mystery, or Historic.', 'your_text_domain') . '</li>' .
'<li>' . __('Specify the correct writer of the book. Remember that the Author module refers to you, the author of this book review.', 'your_text_domain') . '</li>' .
'</ul>' .
'<p>' . __('If you want to schedule the book review to be published in the future:', 'your_text_domain') . '</p>' .
'<ul>' .
'<li>' . __('Under the Publish module, click on the Edit link next to Publish.', 'your_text_domain') . '</li>' .
'<li>' . __('Change the date to the date to actual publish this article, then click on Ok.', 'your_text_domain') . '</li>' .
'</ul>' .
'<p><strong>' . __('For more information:', 'your_text_domain') . '</strong></p>' .
'<p>' . __('<a href="http://codex.wordpress.org/Posts_Edit_SubPanel" target="_blank">Edit Posts Documentation</a>', 'your_text_domain') . '</p>' .
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'your_text_domain') . '</p>' ;
} elseif ( 'edit-book' == $screen->id ) {
$contextual_help =
'<p>' . __('This is the help screen displaying the table of books blah blah blah.', 'your_text_domain') . '</p>' ;
}
return $contextual_help;
}
add_action( 'contextual_help', 'codex_add_help_text', 10, 3 );
Adding WordPress 3.3+ Help Tab:
function codex_custom_help_tab() {
$screen = get_current_screen();
// Return early if we're not on the book post type.
if ( 'book' != $screen->post_type )
return;
// Setup help tab args.
$args = array(
'id' => 'you_custom_id', //unique id for the tab
'title' => 'Custom Help', //unique visible title for the tab
'content' => '<h3>Help Title</h3><p>Help content</p>', //actual help text
);
// Add the help tab.
$screen->add_help_tab( $args );
}
add_action('admin_head', 'codex_custom_help_tab');
Flushing Rewrite on Activation
To get permalinks to work when you activate the plugin use the following example, paying attention to how my_cpt_init is called in the register_activation_hook callback:
add_action( 'init', 'my_cpt_init' );
function my_cpt_init() {
register_post_type( ... );
}
function my_rewrite_flush() {
// First, we "add" the custom post type via the above written function.
// Note: "add" is written with quotes, as CPTs don't get added to the DB,
// They are only referenced in the post_type column with a post entry,
// when you add a post of this CPT.
my_cpt_init();
// ATTENTION: This is *only* done during plugin activation hook in this example!
// You should *NEVER EVER* do this on every page load!!
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );
For themes, you'll need to use the after_switch_theme hook instead. Like so:
add_action( 'init', 'my_cpt_init' );
function my_cpt_init() {
register_post_type( ... );
}
function my_rewrite_flush() {
my_cpt_init();
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_rewrite_flush' );
Notes
- Note that although the $public attribute is optional, the inputs passed to the register_post_type() function are exactly what is queried by the get_post_types() function. So if you verbosely set the equivalent options for publicly_queriable, show_ui, show_in_nav_menus, and exclude_from_search, this will not be handled the same as if you had set the $public attribute. See bug 18950.
Change Log
- 4.7.0:
- Added the `view_items` and `attributes` labels.
- 4.6.0:
- Post type object returned is now an instance of WP_Post_Type.
- 4.4.0:
- The `show_ui` argument is now enforced on the post type listing screen and post editing screen.
- 3.5.0:
- 'supports' argument can be set to Boolean false to disable default title and editor.
- Since 2.9
Source File
register_post_type() is located in wp-includes/post.php
.
Resources
Generators
Plugins
Related
Post Types:
register_post_type(),
add_post_type_support(),
remove_post_type_support(),
post_type_supports(),
post_type_exists(),
set_post_type(),
get_post_type(),
get_post_types(),
get_post_type_object(),
get_post_type_capabilities(),
get_post_type_labels(),
is_post_type_hierarchical(),
is_post_type_archive(),
post_type_archive_title()