複数のカスタム投稿を追加した場合
これでカスタム投稿追加と
カテゴリ、タグまで使えます。
// カスタム投稿タイプ 制作実例
function work_custom_post_type(){
$labels = [
'singular_name' => 'works',
'edit_item' => 'works',
];
$args = array(
'label' => "制作実例", //管理画面に出てくる名前
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'has_archive' => true,
'supports' => array('title','editor','thumbnail'),
'taxonomies' => array('works_category','works_tag')
);
register_post_type('works',$args);
// カスタムタクソノミーを作成
//カテゴリータイプ
$args = [
'label' => 'カテゴリー',
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'hierarchical' => true
];
register_taxonomy('works_category','works',$args);
//タグタイプ
$args = [
'label' => '業種タグ',
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'hierarchical' => false
];
register_taxonomy('works_tag','works',$args);
}
add_action('init', 'work_custom_post_type');
- お仕事のご依頼やお問い合わせはフォームやツイッターにてお気軽にお問い合わせ下さい。
- お問い合わせフォーム
- » 高橋しゃちょー (@osaka_dos) | Twitter