私の人生のために私は私のカスタム投稿タイプでカテゴリーが存在するようになるようには思えません。私のテーマのfunctions.php
ファイルの最後に次のような単純なコードを追加しましたが、カスタム投稿の管理者側からカテゴリが表示されません。
register_post_type("customy", array(
'label' => 'Customy',
'description' => 'Custom stuff for this site.',
'public' => true,
'hierarchical' => true,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'revisions'),
'taxonomies' => array('category')
));
register_taxonomy_for_object_type('category', 'customy');
register_post_type()
はすぐに新しいpost_type
を追加しますが、post_type
に関連するカテゴリ分類のためにロジックを関数に束縛してinit
アクションに追加する必要があるかのようです。実用的な例は次のとおりです。
function add_articles_post_type() {
register_post_type("article", array(
'label' => 'Article',
'public' => true,
'hierarchical' => true,
'supports' => array('title','editor','author','thumbnail','revisions')
));
register_taxonomy_for_object_type('category', 'article');
}
add_action('init', 'add_articles_post_type');