LoginSignup
0
0

More than 1 year has passed since last update.

WordPressでカスタム投稿タイプ作成(functions.php)

Posted at

functions.php

functions.php
//カスタム投稿タイプ
function add_custom_post_type_news()
{
  // お知らせ
  register_post_type(
    'news', // 1.投稿タイプ名 
    array(   // 2.オプション 
      'label' => 'お知らせ', // 投稿タイプの名前
      'public'        => true, // 利用する場合はtrueにする 
      'has_archive'   => true, // この投稿タイプのアーカイブを有効にする
      'menu_position' => 10, // この投稿タイプが表示されるメニューの位置
      'menu_icon'     => 'dashicons-edit', // メニューで使用するアイコン
      'supports' => array( // サポートする機能
        'title',
        'custom-fields',
        'editor',
        'thumbnail',
        'tag'
      ),
      //'show_in_rest' => true,//新しいエディター
    )
  );
  register_taxonomy(
    'genre_category', //分類名
    'news',
    array(
      'label' => 'カテゴリリー',
      'hierarchical' => true,
      //'show_in_rest' => true,

    )
  );
  register_taxonomy(
    'genre_tag', //分類名
    'news',
    array(
      'hierarchical' => false, //タグタイプの指定(階層をもたない)
      'update_count_callback' => '_update_post_term_count',
      'label' => 'タグ',
      'hierarchical' => true,
      //'show_in_rest' => true,

    )
  );
}
add_action('init', 'add_custom_post_type_news');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0