content_copy コードをクリップボードにコピー
function returnPostArgs($array){
  $post_type = $array['post_type'];
  $name = $array['name'];
  $args = array(
    'labels' => [
      'name'          => $name,
      'singular_name' => $post_type,
    ],
    'public'        => true,
    'has_archive'   => true,
    'menu_position' => 5,
    'rewrite'       => array('slug' =>$post_type, 'with_front' => false),
    'supports'      => array( 'title','editor','thumbnail','excerpt')
  );
  return $args;
}

function returnCatArgs($array){
  $name = $array['name'];
  $args = array(
    'hierarchical' => true,
    'label' => $name.'のカテゴリー', 
    'public' => true,
    'show_ui' => true
  );
  return $args;
}

function returnTagArgs($array){
  $name = $array['name'];
  $args = array(
    'hierarchical' => false,
    'label' => $name.'のタグ', 
    'public' => true,
    'show_ui' => true
  );
  return $args;
}

// カスタム投稿「WEB制作」(post_type:web)
$post_web_array = array(
  'post_type' => 'web',
  'name'      => 'WEB制作'
);
function create_post_web($array){
  $post_args = returnPostArgs($array);
  $category_args = returnCatArgs($array);
  $tag_args = returnTagArgs($array);
  // カスタム投稿の設定
  register_post_type($array['post_type'],$post_args);
  // カスタムタクソノミー(カテゴリー)の登録
  register_taxonomy($array['post_type'].'_category',$array['post_type'],$category_args);
  // カスタムタクソノミー(タグ)の設定
  register_taxonomy($array['post_type'].'_tag', $array['post_type'] , $tag_args);
}
add_action('hook_create_post_web', 'create_post_web',10,1);
do_action('hook_create_post_web',$post_web_array);

// カスタム投稿「FX」(post_type:fx)
$post_fx_array = array(
  'post_type' => 'fx',
  'name'      => 'FX'
);
function create_post_fx($array){
  $post_args = returnPostArgs($array);
  $category_args = returnCatArgs($array);
  $tag_args = returnTagArgs($array);
  // カスタム投稿の設定
  register_post_type($array['post_type'],$post_args);
  // カスタムタクソノミー(カテゴリー)の登録
  register_taxonomy($array['post_type'].'_category',$array['post_type'],$category_args);
  // カスタムタクソノミー(タグ)の設定
  register_taxonomy($array['post_type'].'_tag', $array['post_type'] , $tag_args);
}
add_action('hook_create_post_fx', 'create_post_fx',10,1);
do_action('hook_create_post_fx',$post_fx_array);
arrow_circle_up