カスタム投稿タイプの作成
更新日:2011年10月27日
取り急ぎ簡単にメモ。
function.phpに以下のように記述します。
// タクソノミー分類指定
function tax_option_get_pages( $pages, $r ) {
if ( isset( $r['taxonomy'] ) && isset( $r['term'] ) && in_array( $r['taxonomy'], get_object_taxonomies( $r['post_type'] ) ) && get_term_by( ‘slug’, $r['term'], $r['taxonomy'] ) ) {
$excludes = array();
foreach ( $pages as $key => $page ) {
if ( ! is_object_in_term( $page->ID, $r['taxonomy'], $r['term'] ) ) {
unset( $pages[$key] );
if ( is_post_type_hierarchical( $r['post_type'] ) && isset( $r['hide_children'] ) && $r['hide_children'] ) {
$children = get_page_children( $page->ID, $pages );
foreach ( $children as $child ) {
$excludes[] = $child->ID;
}
}
}
}
foreach ( $pages as $key => $page ) {
if ( in_array( $page->ID, $excludes ) ) {
unset( $pages[$key] );
}
}
}
return $pages;
}
add_filter( ‘get_pages’, ‘tax_option_get_pages’, 10, 2 );// イベント情報用 カスタム投稿タイプの設定
function event_postype() {
$labels = array(
‘name’ => ‘イベント情報’,
‘singular_name’ => ‘イベント情報’,
‘add_new’ => ‘新規追加’,
‘add_new_item’ => ‘新規イベント情報を追加’,
‘edit_item’ => ‘イベント情報を編集’,
‘new_item’ => ‘新規イベント情報’,
‘view_item’ => ‘イベント情報を表示’,
‘search_items’ => ‘イベント情報を検索’,
‘not_found’ => ‘投稿されたイベント情報はありません’,
‘not_found_in_trash’ => ‘ゴミ箱にイベント情報はありません。’,
‘parent_item_colon’ => ”,
);
$args = array(
‘label’ => __(‘Events’),
‘labels’ => $labels,
‘public’ => true,
‘menu_position’ => 5,
‘supports’=> array(‘title’, ‘thumbnail’, ‘excerpt’, ‘editor’) ,
‘taxonomies’ => array(‘eventcategory’, ‘post_tag’),
‘has_archive’ => ‘event’
);
register_post_type(‘events’, $args);
}
add_action( ‘init’, ‘event_postype’ );// イベント情報用 タクソノミーの設定
function eventcategory_taxonomy() {
$labels = array(
‘name’ => ‘イベント情報カテゴリー’,
‘singular_name’ => ‘掲載企業イベント情報カテゴリー’,
‘search_items’ => ‘イベント情報を検索’,
‘popular_items’ => ‘よく使われているイベント情報’,
‘all_items’ => ‘すべてのイベント情報’,
‘parent_item’ => null,
‘parent_item_colon’ => null,
‘edit_item’ => ‘イベント情報カテゴリーの編集’,
‘update_item’ => ‘更新’,
‘add_new_item’ => ‘新規イベント情報カテゴリー’,
‘new_item_name’ => ‘新しいイベント情報カテゴリー’
);
register_taxonomy(‘eventcategory’,'events’, array(
‘label’ => ‘イベント情報カテゴリー’,
‘labels’ => $labels,
‘hierarchical’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’ => ‘event-category’),
));
}
add_action( ‘init’, ‘eventcategory_taxonomy’, 0 );
上記で管理画面はOKなハズ。
詳しくは後日解説します。m(_ _)m

