Created
March 15, 2020 06:04
-
-
Save kaoru-fukusato/b78a3e85a2b3ad7ce862abf00e624048 to your computer and use it in GitHub Desktop.
カスタム投稿タイプ、カスタムタクソノミーについて
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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