- サイトデザイン工事中です。ご意見をお寄せください。
- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/register post type
提供:WordPress Codex 日本語版
< 関数リファレンス
タグ一覧: テンプレートタグ | インクルードタグ | 条件分岐タグ | その他の関数 | phpdoc
使い方: テンプレートタグ入門 | パラメータの渡し方 | 初心者の方へ | その他のテーマ関連資料
目次 |
説明
投稿タイプを作成または変更します。init よりも前に register_post_type を使用しないでください。
使い方
<?php register_post_type( $post_type, $args ) ?>
パラメータ
- $post_type
- (文字列) (必須) 投稿タイプ (最大 20 文字)
- 初期値: なし
- $args
- (配列) (オプション) 引数の配列
- 初期値: なし
引数
- label
- (文字列) (オプション) 投稿タイプの翻訳のための複数形の名前。
- 初期値: $post_type
- labels
- (配列) (オプション) labels - この投稿タイプのラベルの配列。デフォルトでは、post labels が非階層タイプに、page labels が階層タイプに使用されます。
- 初期値: 空の場合は、name が label 値にセットされ、singular_name が name 値にセットされます
- 'name' - 投稿タイプの一般名、通常複数形。 The same as, and overridden by $post_type_object->label
- 'singular_name' - この投稿タイプの 1 オブジェクトの名前。name の値のデフォルト。
- 'add_new' - add new テキスト。非階層/階層タイプのどちらもデフォルトは Add New。この文字列を国際化対応にするには、gettext context を投稿タイプにマッチするようにしてください。例:
_x('Add New', 'product'); - 'add_new_item' - add new item テキスト。デフォルトは Add New Post/Add New Page
- 'edit_item' - edit item テキスト。デフォルトは Edit Post/Edit Page
- 'new_item' - new item テキスト。デフォルトは New Post/New Page
- 'view_item' - view item テキスト。デフォルトは View Post/View Page
- 'search_items' - search items テキスト。デフォルトは Search Posts/Search Pages
- 'not_found' - not found テキスト。デフォルトは No posts found/No pages found
- 'not_found_in_trash' - not found in trash テキスト。デフォルトは No posts found in Trash/No pages found in Trash
- 'parent_item_colon' - parent テキスト。非階層タイプでは使用しない。階層タイプではデフォルトは Parent Page:
- description
- (文字列) (オプション) 投稿タイプの簡潔な説明。
- 初期値: blank
- public
- (真偽値) (オプション) publicly_queriable, show_ui, show_in_nav_menus および exclude_from_search のデフォルト値を定義するメタ引数。
- 初期値: false
- 'false' - この投稿タイプでユーザーインターフェースを表示しない(show_ui=false)、post_type クエリがフロントエンドで実行できない(publicly_queryable=false)、検索結果からこの投稿タイプを除外する(exclude_from_search=true)、ナビゲーションメニューで post_type を選択候補から外す(show_in_nav_menus=false)
- 'true' - show_ui=true, publicly_queryable=true, exclude_from_search=false, show_in_nav_menus=true
- publicly_queryable
- (真偽値) (オプション) フロントエンドで post_type クエリが実行可能かどうか。
- 初期値: value of public argument
- exclude_from_search
- (真偽値) (importance) この投稿タイプを検索結果から除外するかどうか。
- 初期値: value of the opposite of the public argument
- show_ui
- (真偽値) (オプション) この投稿タイプを管理するデフォルト UI を生成するかどうか。ビルトイン投稿タイプ(投稿と固定ページ)は、意図的に「偽」に設定してあります。
- 初期値: value of public argument
- 'false' - この投稿タイプのユーザーインターフェースを表示しない
- 'true' - (管理パネルで)この投稿タイプのユーザーインターフェースを表示する
- capability_type
- (文字列) (オプション) 投稿タイプの閲覧/編集/削除権限をチェックするのに使用。
- 初期値: "post"
デフォルトでは capability_type は権限構築に使用します。
- capabilities
- (配列) (オプション) この投稿タイプの権限の配列。
- 初期値: capability_type is used to construct
- 'edit_' . $capability_type (edit_post) - この投稿タイプの特定のオブジェクトを編集を制御するメタ権限。デフォルトは "edit_ . $capability_type"
- 'edit_' . $capability_type . 's' (edit_posts) - この投稿タイプのオブジェクトのクラスとしての編集を制御する権限。デフォルトは "edit_ . $capability_type . s"
- 'edit_others_' . $capability_type . 's' (edit_others_posts) - 他のユーザの所有する(この投稿タイプの)オブジェクトの編集を制御する権限。デフォルトは "edit_others_ . $capability_type . s"
- 'publish_' . $capability_type . 's' (publish_posts) - この投稿タイプのオブジェクトの公開を制御する権限。デフォルトは "publish_ . $capability_type . s"
- 'read_' . $capability_type (read_post) - この投稿タイプの特定のオブジェクトの閲覧を制御するメタ権限。デフォルトは "read_ . $capability_type"
- 'read_private_' . $capability_type . 's' (read_private_posts) - プライベート投稿の閲覧を制御する権限。デフォルトは "read_private . $capability_type . s"
- 'delete_' . $capability_type (delete_post) - この投稿タイプの特定のオブジェクトの削除を制御するメタ権限。デフォルトは "delete_ . $capability_type"
- hierarchical
- (真偽値) (オプション) この投稿タイプが階層(親の指定が許可されている)かどうか。
- 初期値: false
- supports
- (配列) (オプション) add_post_type_support()/en を直接呼び出すエイリアス。
- 初期値: title and editor
- 'title'
- 'editor' (content)
- 'author'
- 'thumbnail' (featured image) (使用中のテーマがアイキャッチ画像/投稿サムネイルをサポートしていることが必要)
- 'excerpt'
- 'trackbacks'
- 'custom-fields'
- 'comments' (編集画面でコメント数バルーンが見える)
- 'revisions' (リビジョンを保存する)
- 'page-attributes' (template and menu order) (hierarchical が true であることが必要)
- register_meta_box_cb
- (文字列) (オプション) 編集フォームのメタボックスをセットアップするのに呼び出すコールバック関数を提供。コールバックで remove_meta_box()/en and add_meta_box() を呼び出す。
- 初期値: なし
- taxonomies
- (配列) (オプション) この投稿タイプで使用する、登録されたタクソノミーの配列。register_taxonomy_for_object_type()/en を直接呼び出す代わりに使用可能。タクソノミーは register_taxonomy()/enで登録する必要がある。
- 初期値: なし
- menu_position
- (整数) (オプション) 投稿タイプが表示されるメニューの位置。
- 初期値: null - デフォルトはコメントの下
- 5 - 投稿の下
- 10 - メディアの下
- 20 - ページの下
- menu_icon
- (文字列) (オプション) このメニューで使用するアイコンの url。
- 初期値: null - デフォルトは投稿アイコン
- permalink_epmask
- (文字列) (オプション) デフォルトの rewrite endpoint bitmasks。詳細は Trac Ticket 12605を参照。
- 初期値: EP_PERMALINK
- rewrite
- (真偽値/配列) (オプション) このフォーマットでパーマリンクをリライトする。
- 初期値: 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
- (真偽値) (オプション) この投稿に使用する query var の名前。
- 初期値: true
- can_export
- (真偽値) (オプション) この投稿タイプをエクスポート可能かどうか。
- 初期値: true
- show_in_nav_menus
- (真偽値) (オプション) ナビゲーションメニューで投稿タイプが選択可能かどうか。
- 初期値: value of public argument
- _builtin
- (真偽値) (not for general use) この投稿タイプがネイティブ、あるいはビルトインかどうか。 注意: この Codex エントリはドキュメント用です。独自の投稿タイプを登録するときにこれを使わないよう、コア開発者は勧めています。
- 初期値: 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
- (真偽値) (not for general use) この投稿タイプのエントリを編集するリンク。 注意: この Codex エントリはドキュメント用です。独自の投稿タイプを登録するときにこれを使わないよう、コア開発者は勧めています。
- 初期値:
- 'post.php?post=%d'
用例
"book" というカスタム投稿タイプを、ヘルプ付きで登録する例です。
<?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;
}
?>
変更履歴
- Since 2.9
ソースファイル
register_post_type() は wp-includes/post.php にあります。
リソース
- Custom Post Types
- Feeds for Custom Post Types (Trac 12943)
- Discussion on wp-hackers about capabilities
- Another discussion on wp-hackers about capabilities
プラグインリソース
最新英語版: WordPress Codex » Function Reference/register_post_type (最新版との差分)