• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「関数リファレンス/register post type」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(リンク等調整)
(原文を最新版に更新。翻訳作業中)
1行目: 1行目:
 
{{NeedTrans}}
 
{{NeedTrans}}
{{Draft}}
 
 
{{テンプレートタグガイド|PHP}}
 
{{テンプレートタグガイド|PHP}}
== Description ==
 
  
Create or modify a [[用語集#Post Type|post type]]. The function will accept an array ([[#$args|second optional parameter]]), along with a string for the post type name.
+
== 説明 ==
Do not use before init.
+
Create or modify a [[用語集#Post Type|post type]]. Do not use ''register_post_type'' before init.
 
+
== Usage ==
+
  
 +
== 使い方 ==
 
  <?php register_post_type( $post_type, $args ) ?>
 
  <?php register_post_type( $post_type, $args ) ?>
 
+
== パラメータ ==
== Parameters ==
+
{{Parameter|$post_type|string|Post type. (max. 20 characters)}}
 
+
{{Parameter|$post_type|string|Post type.}}
+
 
{{Parameter|$args|array|An array of arguments.|optional}}
 
{{Parameter|$args|array|An array of arguments.|optional}}
  
=== $args ===
+
=== 引数 ===
Known Parameters for $args are:
+
 
+
 
{{Parameter|label|string|A '''plural''' descriptive name for the post type marked for translation.|optional|$post_type}}
 
{{Parameter|label|string|A '''plural''' descriptive name for the post type marked for translation.|optional|$post_type}}
  
{{Parameter|singular_label|string|A '''singular''' descriptive name for the post type marked for translation.|optional|$label}}
+
{{Parameter|labels|array|labels - An array of labels for this post type. By default post labels are used for non-hierarchical types and page labels for hierarchical ones.|optional|if empty, name is set to label value, and singular_name is set to name value}}
 +
:* 'name' - general name for the post type, usually plural. The same as,  and overridden by $post_type_object->label
 +
:* 'singular_name' - name for one object of this post type. Defaults to value of name
 +
:* 'add_new' -  the add new text.  The default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a [[I18n_for_WordPress_Developers#Disambiguation_by_context|gettext context]] matching your post type. Example: <code>_x('Add New', 'product');</code>
 +
:* 'add_new_item' -  the add new item text.  Default is Add New Post/Add New Page
 +
:* 'edit_item' - the edit item text. Default is Edit Post/Edit Page
 +
:* 'new_item' - the new item text.  Default is New Post/New Page
 +
:* 'view_item' - the view item text.  Default is View Post/View Page
 +
:* 'search_items' - the search items text. Default is Search Posts/Search Pages
 +
:* 'not_found' - the not found text. Default is No posts found/No pages found
 +
:* 'not_found_in_trash' - the not found in trash text. Default is No posts found in Trash/No pages found in Trash
 +
:* 'parent_item_colon' - the parent text.  This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page:
  
 
{{Parameter|description|string|A short descriptive summary of what the post type is.|optional|blank}}
 
{{Parameter|description|string|A short descriptive summary of what the post type is.|optional|blank}}
  
{{Parameter|public|boolean|Whether posts of this type should be shown in the admin UI.|optional|false}}
+
{{Parameter|public|boolean|Meta argument used to define default values for publicly_queriable, show_ui, show_in_nav_menus and exclude_from_search.|optional|false}}
 +
:* 'false' - do not display a user-interface for this post type (show_ui=false), post_type queries can not be performed from the front end (publicly_queryable=false), exclude posts with this post type from search results (exclude_from_search=true), hide post_type for selection in navigation menus (show_in_nav_menus=false)
 +
:* 'true' - show_ui=true, publicly_queryable=true, exclude_from_search=false, show_in_nav_menus=true
  
{{Parameter|publicly_queryable|boolean|Whether post_type queries can be performed from the front page.|optional|Whatever public is set as.}}
+
{{Parameter|publicly_queryable|boolean|Whether post_type queries can be performed from the front end.|optional|value of public argument}}
  
{{Parameter|exclude_from_search|boolean|Whether to exclude posts with this post type from search results.|importance|'''true''' if the type is not public, '''false''' if the type is public}}
+
{{Parameter|exclude_from_search|boolean|Whether to exclude posts with this post type from search results.|importance|value of the opposite of the public argument}}
  
{{Parameter|show_ui|boolean|Whether to generate a default UI for managing this post type.|optional|if not set, defaults to value of public argument}}
+
{{Parameter|show_ui|boolean|Whether to generate a default UI for managing this post type.  Note that _built-in post types, such as post and page, are intentionally set to false.|optional|value of public argument}}
 
:* 'false' - do not display a user-interface for this post type
 
:* 'false' - do not display a user-interface for this post type
 
:* 'true' - display a user-interface (admin panel) for this post type
 
:* 'true' - display a user-interface (admin panel) for this post type
  
<!--Note - not sure this is used {{Parameter|inherit_type|string|The post type from which to inherit the edit link and capability type.|optional}}-->
 
 
{{Parameter|capability_type|string|The post type to use for checking read, edit, and delete capabilities.|optional|"post"}}
 
{{Parameter|capability_type|string|The post type to use for checking read, edit, and delete capabilities.|optional|"post"}}
 +
By default the capability_type is used to construct capabilities.
  
{{Parameter|edit_cap|string|The capability that controls editing a particular object of this post type.|optional|"edit_$capability_type" (edit_post).}}
+
{{Parameter|capabilities|array|An array of the capabilities for this post type.|optional|capability_type is used to construct}}
 +
:* 'edit_'        . $capability_type      (edit_post) - The meta capability that controls editing a particular object of this post type. Defaults to "edit_ . $capability_type"
 +
:* 'edit_'        . $capability_type . 's' (edit_posts) - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s"
 +
:* 'edit_others_'  . $capability_type . 's' (edit_others_posts) - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s"
 +
:* 'publish_'      . $capability_type . 's' (publish_posts) - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s"
 +
:* 'read_'        . $capability_type      (read_post) - The meta capability that controls reading a particular object of this post type. Defaults to "read_ . $capability_type"
 +
:* 'read_private_' . $capability_type . 's' (read_private_posts) - The capability that controls reading private posts. Defaults to "read_private . $capability_type . s"
 +
:* 'delete_'      . $capability_type      (delete_post) - The meta capability that controls deleting a particular object of this post type. Defaults to "delete_ . $capability_type"
  
{{Parameter|edit_type_cap|string|The capability that controls editing objects of this post type as a class.|optional|"edit_ . $capability_type . s" (edit_posts).}}
+
{{Parameter|hierarchical|boolean|Whether the post type is hierarchical. Allows Parent to be specified.|optional|false}}
  
{{Parameter|edit_others_cap|string|The capability that controls editing objects of this post type that are owned by other users.|optional|"edit_others_ . $capability_type . s" (edit_others_posts).}}
+
{{Parameter|supports|array|An alias for calling [[関数リファレンス/add_post_type_support|add_post_type_support()]]/[[:en:Function Reference/add_post_type_support|en]] directly.|optional|title and editor}}
 
+
{{Parameter|publish_others_cap|string|The capability that controls publishing objects of this post type.|optional|"publish_ . $capability_type . s" (publish_posts).}}
+
 
+
{{Parameter|read_cap|string|The capability that controls reading a particular object of this post type.|optional|"read_$capability_type" (read_post).}}
+
 
+
{{Parameter|delete_cap|string|The capability that controls deleting a particular object of this post type.|optional|"delete_$capability_type" (delete_post).}}
+
 
+
{{Parameter|hierarchical|boolean|Whether the post type is hierarchical.|optional|false}}
+
 
+
{{Parameter|supports|array|An alias for calling [[関数リファレンス/add_post_type_support|add_post_type_support()]]/[[:en:Function Reference/add_post_type_support|en]] directly.
+
 
:* 'title'
 
:* 'title'
 
:* 'editor' (content)
 
:* 'editor' (content)
 
:* 'author'
 
:* 'author'
:* 'thumbnail'
+
:* 'thumbnail' (featured image) (current theme must also support post-thumbnails)
:* 'excerpts'
+
:* 'excerpt'
 
:* 'trackbacks'
 
:* 'trackbacks'
 
:* 'custom-fields'
 
:* 'custom-fields'
:* 'comments'
+
:* 'comments' (also will see comment count balloon on edit screen)
:* 'revisions'
+
:* 'revisions' (will store revisions)
:* 'page-attributes' (parent, template, and menu order)
+
:* 'page-attributes' (template and menu order) (hierarchical must be true)
|optional}}
+
  
 
{{Parameter|register_meta_box_cb|string|Provide a callback function that will be called when setting up the meta boxes for the edit form. Do [[関数リファレンス/remove_meta_box|remove_meta_box()]]/[[:en:Function Reference/remove_meta_box|en]] and [[関数リファレンス/add_meta_box|add_meta_box()]] calls in the callback.|optional}}
 
{{Parameter|register_meta_box_cb|string|Provide a callback function that will be called when setting up the meta boxes for the edit form. Do [[関数リファレンス/remove_meta_box|remove_meta_box()]]/[[:en:Function Reference/remove_meta_box|en]] and [[関数リファレンス/add_meta_box|add_meta_box()]] calls in the callback.|optional}}
  
{{Parameter|taxonomies|array|An array of taxonomy identifiers that will be registered for the post type. Taxonomies can be registered later with [[関数リファレンス/register_taxonomy|register_taxonomy()]]/[[:en:Function Reference/register_taxonomy|en]] or [[関数リファレンス/register_taxonomy_for_object_type|register_taxonomy_for_object_type()]]/[[:en:Function Reference/register_taxonomy_for_object_type|en]].|optional}}
+
{{Parameter|taxonomies|array|An array of registered taxonomies that will be used with this post type. This can be use in lieu of calling [[関数リファレンス/register_taxonomy_for_object_type|register_taxonomy_for_object_type()]]/[[:en:Function Reference/register_taxonomy_for_object_type|en]] directly.  Taxonomies still need to be registered with [[関数リファレンス/register_taxonomy|register_taxonomy()]]/[[:en:Function Reference/register_taxonomy|en]].|optional}}
  
{{Parameter|menu_postition|string|The position in the menu order the post type should appear. |optional|null - defaults to the bottom}}
+
{{Parameter|menu_position|integer|The position in the menu order the post type should appear. |optional|null - defaults to below Comments}}
 +
:* 5  - below Posts
 +
:* 10 - below Media
 +
:* 20 - below Pages
  
 
{{Parameter|menu_icon|string|The url to the icon to be used for this menu.|optional|null - defaults to the posts icon}}
 
{{Parameter|menu_icon|string|The url to the icon to be used for this menu.|optional|null - defaults to the posts icon}}
  
{{Parameter|permalink_epmask|string|The url to the icon to be used for this menu.|optional|EP_NONE}}
+
{{Parameter|permalink_epmask|string|The default rewrite endpoint bitmasks. For more info see [http://core.trac.wordpress.org/ticket/12605 Trac Ticket 12605].|optional|EP_PERMALINK}}
  
{{Parameter|rewrite|array|Rewrite permalinks with this format.|optional|false}}
+
{{Parameter|rewrite|boolean or array|Rewrite permalinks with this format.|optional|true}}
:* 'slug' - defaults to post_type
+
:$args array
:* 'with_front' - defaults to true
+
:* 'slug' - prepend posts with this slug - defaults to post type's name
 +
:* 'with_front' - allowing permalinks to be prepended with front base - defaults to true
  
{{Parameter|query_var|boolean|Name of the query var to use for this post type.|optional|false}}
+
{{Parameter|query_var|boolean|Name of the query var to use for this post type.|optional|true}}
 +
 
 +
{{Parameter|can_export|boolean|Can this post_type be exported.|optional|true}}
 +
 
 +
{{Parameter|show_in_nav_menus|boolean|Whether post_type is available for selection in navigation menus.|optional|value of public argument}}
  
 
{{Parameter|_builtin|boolean|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'''|not for general use|false}}
 
{{Parameter|_builtin|boolean|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'''|not for general use|false}}
85行目: 95行目:
 
:* 'true' - this is a built-in native post type (post, page, attachment, revision, nav_menu_item)
 
:* 'true' - this is a built-in native post type (post, page, attachment, revision, nav_menu_item)
  
{{Parameter|__edit_link|boolean|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'''|not for general use|}}
+
{{Parameter|_edit_link|boolean|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'''|not for general use|}}
 
:* 'post.php?post=%d'
 
:* 'post.php?post=%d'
  
== Example ==
+
== 用例 ==
 +
An an example of registering a post type called "book" including providing contextual help:
 
<pre>
 
<pre>
<?php  
+
<?php
 +
add_action('init', 'my_custom_init');
 +
function my_custom_init()
 +
{
 +
  $labels = array(
 +
    'name' => _x('Books', 'post type general name'),
 +
    'singular_name' => _x('Book', 'post type singular name'),
 +
    'add_new' => _x('Add New', 'book'),
 +
    'add_new_item' => __('Add New Book'),
 +
    'edit_item' => __('Edit Book'),
 +
    'new_item' => __('New Book'),
 +
    'view_item' => __('View Book'),
 +
    'search_items' => __('Search Books'),
 +
    'not_found' =>  __('No books found'),
 +
    'not_found_in_trash' => __('No books found in Trash'),
 +
    'parent_item_colon' => ''
 +
  );
 +
  $args = array(
 +
    'labels' => $labels,
 +
    'public' => true,
 +
    'publicly_queryable' => true,
 +
    'show_ui' => true,
 +
    'query_var' => true,
 +
    'rewrite' => true,
 +
    'capability_type' => 'post',
 +
    'hierarchical' => false,
 +
    'menu_position' => null,
 +
    'supports' => array('title','editor','author','thumbnail','excerpt','comments')
 +
  );
 +
  register_post_type('book',$args);
 +
}
 +
 
 +
//add filter to insure the text Book, or book, is displayed when user updates a book
 +
add_filter('post_updated_messages', 'book_updated_messages');
 +
function book_updated_messages( $messages ) {
 +
 
 +
  $messages['book'] = array(
 +
    0 => '', // Unused. Messages start at index 1.
 +
    1 => sprintf( __('Book updated. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
 +
    2 => __('Custom field updated.'),
 +
    3 => __('Custom field deleted.'),
 +
    4 => __('Book updated.'),
 +
    /* translators: %s: date and time of the revision */
 +
    5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
 +
    6 => sprintf( __('Book published. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
 +
    7 => __('Book saved.'),
 +
    8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
 +
    9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>'),
 +
      // translators: Publish box date format, see http://php.net/date
 +
      date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
 +
    10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
 +
  );
  
$args = array(
+
  return $messages;
        'label' => __('Albums'),
+
}
        'singular_label' => __('Album'),
+
        'public' => true,
+
        'show_ui' => true,
+
        'capability_type' => 'page',
+
        'hierarchical' => false,
+
        'rewrite' => true,
+
        'query_var' => 'album',
+
        'supports' => array('title', 'thumbnail')
+
        );
+
  
register_post_type( 'album' , $args );
+
//display contextual help for Books
 +
add_action( 'contextual_help', 'add_help_text', 10, 3 );
  
 +
function 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:') . '</p>' .
 +
      '<ul>' .
 +
      '<li>' . __('Specify the correct genre such as Mystery, or Historic.') . '</li>' .
 +
      '<li>' . __('Specify the correct writer of the book.  Remember that the Author module refers to you, the author of this book review.') . '</li>' .
 +
      '</ul>' .
 +
      '<p>' . __('If you want to schedule the book review to be published in the future:') . '</p>' .
 +
      '<ul>' .
 +
      '<li>' . __('Under the Publish module, click on the Edit link next to Publish.') . '</li>' .
 +
      '<li>' . __('Change the date to the date to actual publish this article, then click on Ok.') . '</li>' .
 +
      '</ul>' .
 +
      '<p><strong>' . __('For more information:') . '</strong></p>' .
 +
      '<p>' . __('<a href="http://codex.wordpress.org/Posts_Edit_SubPanel" target="_blank">Edit Posts Documentation</a>') . '</p>' .
 +
      '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ;
 +
  } elseif ( 'edit-book' == $screen->id ) {
 +
    $contextual_help =
 +
      '<p>' . __('This is the help screen displaying the table of books blah blah blah.') . '</p>' ;
 +
  }
 +
  return $contextual_help;
 +
}
 
?>
 
?>
 
</pre>
 
</pre>
113行目: 190行目:
 
* Since [[Version 2.9|2.9]]
 
* Since [[Version 2.9|2.9]]
  
== Source File ==
+
== ソースファイル ==
 
<tt>register_post_type()</tt> is located in {{Trac|wp-includes/post.php}}.
 
<tt>register_post_type()</tt> is located in {{Trac|wp-includes/post.php}}.
  
== Resources ==
+
== リソース ==
 +
* [[Custom Post Types]]
 +
* [http://core.trac.wordpress.org/ticket/12943 Feeds for Custom Post Types (Trac 12943)]
 +
* [http://lists.automattic.com/pipermail/wp-hackers/2010-June/032655.html Discussion on wp-hackers about capabilities]
 +
* [http://lists.automattic.com/pipermail/wp-hackers/2010-June/032657.html Another discussion on wp-hackers about capabilities]
 +
===プラグインリソース===
 +
* [http://wordpress.org/extend/plugins/custom-post-type-ui/ Custom Post Type UI Plugin]
 +
* [http://wordpress.org/extend/plugins/cms-press/ CMS Press]
 +
* [http://wordpress.org/extend/plugins/gd-taxonomies-tools/ GD Custom Posts And Taxonomies Tools]
  
* [http://wpengineer.com/impressions-of-custom-post-type/ First Impressions of Custom Post Types]
 
* [http://kovshenin.com/archives/custom-post-types-in-wordpress-3-0/ Custom Post Types in WordPress 3.0]
 
* [http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/ Extending Custom Post Types in WordPress 3.0]
 
* [http://wordpress.org/extend/plugins/custom-post-type-ui/ Custom Post Type UI Plugin - create and administer custom post types and custom taxonomies]
 
  
{{原文|Function Reference/register_post_type|85701}}<!-- 14:38, 10 April 2010 Bono 版 -->
+
{{原文|Function Reference/register_post_type|91386}}<!-- 18:37, 17 July 2010 Dz0ny 版 -->
  
== Related ==
+
== 関連 ==
 +
{{Post Type Tags}}
  
 
{{Tag Footer}}
 
{{Tag Footer}}

2010年7月28日 (水) 06:54時点における版

このページ「関数リファレンス/register post type」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

説明

Create or modify a post type. Do not use register_post_type before init.

使い方

<?php register_post_type( $post_type, $args ) ?>

パラメータ

$post_type
string) (必須) Post type. (max. 20 characters)
初期値: なし
$args
array) (optional) An array of arguments.
初期値: なし

引数

label
string) (optional) A plural descriptive name for the post type marked for translation.
初期値: $post_type
labels
array) (optional) labels - An array of labels for this post type. By default post labels are used for non-hierarchical types and page labels for hierarchical ones.
初期値: if empty, name is set to label value, and singular_name is set to name value
  • 'name' - general name for the post type, usually plural. The same as, and overridden by $post_type_object->label
  • 'singular_name' - name for one object of this post type. Defaults to value of name
  • 'add_new' - the add new text. The default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a gettext context matching your post type. Example: _x('Add New', 'product');
  • 'add_new_item' - the add new item text. Default is Add New Post/Add New Page
  • 'edit_item' - the edit item text. Default is Edit Post/Edit Page
  • 'new_item' - the new item text. Default is New Post/New Page
  • 'view_item' - the view item text. Default is View Post/View Page
  • 'search_items' - the search items text. Default is Search Posts/Search Pages
  • 'not_found' - the not found text. Default is No posts found/No pages found
  • 'not_found_in_trash' - the not found in trash text. Default is No posts found in Trash/No pages found in Trash
  • 'parent_item_colon' - the parent text. This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page:
description
string) (optional) A short descriptive summary of what the post type is.
初期値: blank
public
boolean) (optional) Meta argument used to define default values for publicly_queriable, show_ui, show_in_nav_menus and exclude_from_search.
初期値: false
  • 'false' - do not display a user-interface for this post type (show_ui=false), post_type queries can not be performed from the front end (publicly_queryable=false), exclude posts with this post type from search results (exclude_from_search=true), hide post_type for selection in navigation menus (show_in_nav_menus=false)
  • 'true' - show_ui=true, publicly_queryable=true, exclude_from_search=false, show_in_nav_menus=true
publicly_queryable
boolean) (optional) Whether post_type queries can be performed from the front end.
初期値: value of public argument
exclude_from_search
boolean) (importance) Whether to exclude posts with this post type from search results.
初期値: value of the opposite of the public argument
show_ui
boolean) (optional) Whether to generate a default UI for managing this post type. Note that _built-in post types, such as post and page, are intentionally set to false.
初期値: 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
capability_type
string) (optional) The post type to use for checking read, edit, and delete capabilities.
初期値: "post"

By default the capability_type is used to construct capabilities.

capabilities
array) (optional) An array of the capabilities for this post type.
初期値: capability_type is used to construct
  • 'edit_' . $capability_type (edit_post) - The meta capability that controls editing a particular object of this post type. Defaults to "edit_ . $capability_type"
  • 'edit_' . $capability_type . 's' (edit_posts) - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s"
  • 'edit_others_' . $capability_type . 's' (edit_others_posts) - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s"
  • 'publish_' . $capability_type . 's' (publish_posts) - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s"
  • 'read_' . $capability_type (read_post) - The meta capability that controls reading a particular object of this post type. Defaults to "read_ . $capability_type"
  • 'read_private_' . $capability_type . 's' (read_private_posts) - The capability that controls reading private posts. Defaults to "read_private . $capability_type . s"
  • 'delete_' . $capability_type (delete_post) - The meta capability that controls deleting a particular object of this post type. Defaults to "delete_ . $capability_type"
hierarchical
boolean) (optional) Whether the post type is hierarchical. Allows Parent to be specified.
初期値: false
supports
array) (optional) An alias for calling add_post_type_support()/en directly.
初期値: 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' (template and menu order) (hierarchical must be true)
register_meta_box_cb
string) (optional) Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box()/en and add_meta_box() calls in the callback.
初期値: なし
taxonomies
array) (optional) An array of registered taxonomies that will be used with this post type. This can be use in lieu of calling register_taxonomy_for_object_type()/en directly. Taxonomies still need to be registered with register_taxonomy()/en.
初期値: なし
menu_position
integer) (optional) The position in the menu order the post type should appear.
初期値: null - defaults to below Comments
  • 5 - below Posts
  • 10 - below Media
  • 20 - below Pages
menu_icon
string) (optional) The url to the icon to be used for this menu.
初期値: null - defaults to the posts icon
permalink_epmask
string) (optional) The default rewrite endpoint bitmasks. For more info see Trac Ticket 12605.
初期値: EP_PERMALINK
rewrite
boolean or array) (optional) Rewrite permalinks with this format.
初期値: true
$args array
  • 'slug' - prepend posts with this slug - defaults to post type's name
  • 'with_front' - allowing permalinks to be prepended with front base - defaults to true
query_var
boolean) (optional) Name of the query var to use for this post type.
初期値: true
can_export
boolean) (optional) Can this post_type be exported.
初期値: true
show_in_nav_menus
boolean) (optional) Whether post_type is available for selection in navigation menus.
初期値: value of public argument
_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
初期値: 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
初期値:
  • 'post.php?post=%d'

用例

An an example of registering a post type called "book" including providing contextual help:

<?php
add_action('init', 'my_custom_init');
function my_custom_init() 
{
  $labels = array(
    'name' => _x('Books', 'post type general name'),
    'singular_name' => _x('Book', 'post type singular name'),
    'add_new' => _x('Add New', 'book'),
    'add_new_item' => __('Add New Book'),
    'edit_item' => __('Edit Book'),
    'new_item' => __('New Book'),
    'view_item' => __('View Book'),
    'search_items' => __('Search Books'),
    'not_found' =>  __('No books found'),
    'not_found_in_trash' => __('No books found in Trash'), 
    'parent_item_colon' => ''
  );
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','editor','author','thumbnail','excerpt','comments')
  ); 
  register_post_type('book',$args);
}

//add filter to insure the text Book, or book, is displayed when user updates a book 
add_filter('post_updated_messages', 'book_updated_messages');
function book_updated_messages( $messages ) {

  $messages['book'] = array(
    0 => '', // Unused. Messages start at index 1.
    1 => sprintf( __('Book updated. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
    2 => __('Custom field updated.'),
    3 => __('Custom field deleted.'),
    4 => __('Book updated.'),
    /* translators: %s: date and time of the revision */
    5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    6 => sprintf( __('Book published. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
    7 => __('Book saved.'),
    8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>'),
      // translators: Publish box date format, see http://php.net/date
      date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
  );

  return $messages;
}

//display contextual help for Books
add_action( 'contextual_help', 'add_help_text', 10, 3 );

function 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:') . '</p>' .
      '<ul>' .
      '<li>' . __('Specify the correct genre such as Mystery, or Historic.') . '</li>' .
      '<li>' . __('Specify the correct writer of the book.  Remember that the Author module refers to you, the author of this book review.') . '</li>' .
      '</ul>' .
      '<p>' . __('If you want to schedule the book review to be published in the future:') . '</p>' .
      '<ul>' .
      '<li>' . __('Under the Publish module, click on the Edit link next to Publish.') . '</li>' .
      '<li>' . __('Change the date to the date to actual publish this article, then click on Ok.') . '</li>' .
      '</ul>' .
      '<p><strong>' . __('For more information:') . '</strong></p>' .
      '<p>' . __('<a href="http://codex.wordpress.org/Posts_Edit_SubPanel" target="_blank">Edit Posts Documentation</a>') . '</p>' .
      '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ;
  } elseif ( 'edit-book' == $screen->id ) {
    $contextual_help = 
      '<p>' . __('This is the help screen displaying the table of books blah blah blah.') . '</p>' ;
  }
  return $contextual_help;
}
?>

変更履歴

ソースファイル

register_post_type() is located in wp-includes/post.php.

リソース

プラグインリソース


最新英語版: WordPress Codex » Function Reference/register_post_type最新版との差分

関連

投稿タイプ: 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()


関数リファレンステンプレートタグ目次もご覧ください。