映画のエンドロール観る派?観ない派?

ワードプレス初心者です。
子テーマのfunctions.phpに、2種のカスタム投稿を追加(”お知らせ”と”カスタム”という項目で)コードを書き実装できましたが、タクソノミーの方はなぜか”お知らせ”の方にしか追加できずに困っています。
どのようにコードを書けばいいのか、教えていただけたら嬉しいです。

以下これが私が書いた(ググって、コピペしたもの)ものです。よろしくお願いいたします。

//1.子テーマの設定
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
//2.カスタム投稿

function add_custom_post() {
register_post_type(
'infopage',
array(
'label' => 'お知らせ',
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'supports' => array(
'title',
'editor',
'thumbnail',
'revisions',
'excerpt',
'custom-fields',
)
)
);

register_post_type(
'custom',
array(
'label' => 'カスタム',
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'supports' => array(
'title',
'editor',
'thumbnail',
'revisions',
'excerpt',
'custom-fields',
)
)
);

}
add_action('init', 'add_custom_post');

/////////////////////////

function add_taxonomy() {
//お知らせカテゴリ
register_taxonomy(
'info-cat',
'infopage',
array(
'label' => 'お知らせカテゴリ',
'singular_label' => 'お知らせカテゴリ',
'labels' => array(
'all_items' => 'お知らせカテゴリ一覧',
'add_new_item' => 'お知らせカテゴリを追加'
),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'hierarchical' => true
)
);

//お知らせタグ
register_taxonomy(
'info-tag',
'infopage',
array(
'label' => 'お知らせのタグ',
'singular_label' => 'お知らせのタグ',
'labels' => array(
'add_new_item' => 'お知らせのタグを追加'
),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'hierarchical' => false
)
);
}
add_action( 'init', 'add_taxonomy' );

A 回答 (1件)

なにか他に書かれたコードはあるのでしょうか。

みたかぎり、「お知らせ」の分しかコードが書かれていないようです。

同じ「お知らせカテゴリ」「お知らせタグ」を「カスタム」にもつけたいなら、

//お知らせカテゴリ
register_taxonomy(
'info-cat',
array( 'infopage','custom'), //ここを変更

//お知らせタグ
register_taxonomy(
'info-tag',
array( 'infopage','custom'), //同じようにここを変更

別のカテゴリ、タグをつけたいなら、今書かれているコードをつけたいカテゴリ、タグで「カスタム」用に作って付け足してください。
例えば、

//カスタムカテゴリ
register_taxonomy(
'custom-cat', //タクソノミーのスラッグ
'custom', //つけたいポストタイプ
array(
'label' => 'カスタムカテゴリ',
'singular_label' => 'カスタムカテゴリ',
'labels' => array(
'all_items' => 'カスタムカテゴリ一覧',
'add_new_item' => 'カスタムカテゴリを追加'
),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'hierarchical' => true
)
);

参考まで。
    • good
    • 0
この回答へのお礼

教えていただいてありがとうございます!(お礼遅くなってごめんなさい)

お礼日時:2020/05/08 09:28

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!