Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaoru-fukusato/b78a3e85a2b3ad7ce862abf00e624048 to your computer and use it in GitHub Desktop.
Save kaoru-fukusato/b78a3e85a2b3ad7ce862abf00e624048 to your computer and use it in GitHub Desktop.
カスタム投稿タイプ、カスタムタクソノミーについて
//functions.phpへ直書き
/* カスタム投稿タイプ */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type(
'item', /* 投稿タイプのslug */
array(
'labels' => array(
'name' => __( 'おすすめ商品' ),
'singular_name' => __( 'おすすめ商品' )
),
'public' => true,
'menu_position' => 5,
'supports' => array('title','editor','thumbnail','custom-fields','excerpt','author','trackbacks','comments','revisions','page-attributes') /* いろんな機能を有効化 */
)
);
/* カスタムタクソノミー1 */
register_taxonomy(
'item-category', /* タクソノミーのslug */
'item', /* 属する投稿タイプ */
array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'label' => 'カテゴリー',
'singular_label' => 'カテゴリー',
'public' => true,
'show_ui' => true
)
);
/* カスタムタクソノミー2 */
register_taxonomy(
'item-maker', /* タクソノミーのslug */
'item', /* 属する投稿タイプ */
array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'label' => 'メーカー',
'singular_label' => 'メーカー',
'public' => true,
'show_ui' => true
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment