完成イメージ

カスタム投稿

作業内容

functions.phpに、以下の記述を追加する。
形式・パラメータの詳細は、下記のリファレンスを参照。

add_action( 'init', 'create_post_type01' );
function create_post_type01() {
register_post_type( 'xxxxxx_post', //カスタム投稿名
array(
'labels' => array(
'name' => __( 'カスタム投稿' ), //メニューラベル
'singular_name' => __( 'カスタム投稿' ),
'add_new_item' => __('カスタム投稿を追加'),
'edit_item' => __('カスタム投稿を編集'),
'new_item' => __('カスタム投稿を追加')
),
'public' => true, //投稿の公開
'supports' => array('title','editor'), //タイトル・本文有効化
'menu_position' =>20, //メニューの位置
'show_ui' => true, //カスタム投稿タイプ表示
'has_archive' => false, //アーカイブ生成
'hierarchical' => false, //階層構造有無
'show_in_rest' => true, //Gutenberg(ブロックエディタ)対応
'rewrite' => array('with_front' => false), //パーマリンク設定
)
);
register_taxonomy(
'xxxxxx_post_cat',//カスタムタクソノミー
'xxxxxx_post',//適用先(カスタム投稿の場合はカスタム投稿名)
array(
'hierarchical' => true, //階層構造有無
'label' => 'カスタム投稿カテゴリー', //メニューラベル
'singular_label' => 'カスタム投稿カテゴリー', //メニューラベル
'public' => true, //検索可否
'show_ui' => true //ターム管理UIオン(デフォルトUI)
)
);
}