Skip to content

Instantly share code, notes, and snippets.

@ShinichiNishikawa
Created March 12, 2012 17:17
Show Gist options
  • Save ShinichiNishikawa/2023455 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/2023455 to your computer and use it in GitHub Desktop.
カスタム投稿タイプmenuを登録して、カスタムタクソノミgohantypeを紐付けるfunctions.php
<?php
add_action( 'init', 'create_customeposttype_menu' );
function create_customeposttype_menu() {
$label_arr = array(
'name' => 'メニュー',
'singular_name' => 'メニュー',
'search_items' => 'メニューを検索する',
// 'parent_item_colon' => '' //非階層タイプでは利用しない
);
$conf_array = array(
'labels' => $label_arr,
'public' => true, // とにかくtrueにしとくべし。検索できたりQueryいじったりできなくなる
'publicly_queryable' => true, // Query操作したいからtrue
'show_ui' => true, // falseだとUIが表示されない
'query_var' => false, //
'rewrite' => true, //
'capability_type' => 'post', // 権限タイプ post なら投稿権限がある人に表示される的な
'hierarchical' => false, // 親子があるかどうか trueだとページ、falseだと投稿みたいになるのか
'menu_position' => 5, // 5投稿、10メディア、15リンク、20固定ページ、25コメント、60外観、65プラグイン、70ユーザ、75ツール、80設定、100最下部に独立
// 'supports' => array('title','editor','thumbnail','custom-fields','excerpt','author','trackbacks','comments','revisions','page-attributes'), //page-attributesはhierarchicalがtrueじゃないとだめ
'supports' => array('title','editor','custom-fields'),
// 'menu_icon' => '', // url
'rewrite' => true, // rewriteするかどうか
'show_in_nav_menus' => true, // ナビゲーションメニューに表示するかどうか
'has_archive' => true,
);
register_post_type( 'menu', $conf_array );
}
add_action( 'init', 'add_gohantype' );
function add_gohantype() {
// create a new taxonomy
register_taxonomy(
'gohan-type',
'menu',
array(
'label' => 'ごはんタイプ',
'show_ui' => true,
'query_var' => true,
'sort' => true,
'hierarchical' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'gohan-type' ),
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment