Skip to content

Instantly share code, notes, and snippets.

@1shiharat
Created March 19, 2014 03:49
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 1shiharat/9635143 to your computer and use it in GitHub Desktop.
Save 1shiharat/9635143 to your computer and use it in GitHub Desktop.
custom taxonomy create.
// Register Custom Taxonomy
function news_custom_taxonomy() {
$labels = array(
'name' => _x( 'ニュースカテゴリ', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'ニュースカテゴリ', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'ニュースカテゴリ', 'text_domain' ),
'all_items' => __( 'すべてのニュースカテゴリ', 'text_domain' ),
'parent_item' => __( '親カテゴリ', 'text_domain' ),
'parent_item_colon' => __( '親カテゴリ:', 'text_domain' ),
'new_item_name' => __( '新しいカテゴリ', 'text_domain' ),
'add_new_item' => __( '新しいカテゴリを追加', 'text_domain' ),
'edit_item' => __( 'カテゴリを編集', 'text_domain' ),
'update_item' => __( 'カテゴリを更新', 'text_domain' ),
'separate_items_with_commas' => __( 'アイテムをカンマで区切る', 'text_domain' ),
'search_items' => __( 'カテゴリを検索', 'text_domain' ),
'add_or_remove_items' => __( '追加、または削除', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used items', 'text_domain' ),
'not_found' => __( '見つかりませんでした。', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'news_category', array( 'news' ), $args );
}
// Hook into the 'init' action
add_action( 'init', 'news_custom_taxonomy', 0 );
@alexanderbiscajin
Copy link

You can create custom taxonomy in WordPress using this simple code in functions.php

add_action( 'init', 'create_cw_hierarchical_taxonomy', 0 );
//create a custom taxonomy name
function create_cw_hierarchical_taxonomy() {
$labels = array(
'name' => _x( 'Topics', 'taxonomy general name' ),
'singular_name' => _x( 'Topic', 'taxonomy singular name' ),
'search_items' => __( 'Search Topics' ),
'all_items' => __( 'All Topics' ),
'parent_item' => __( 'Parent Topic' ),
'parent_item_colon' => __( 'Parent Topic:' ),
'edit_item' => __( 'Edit Topic' ),
'update_item' => __( 'Update Topic' ),
'add_new_item' => __( 'Add New Topic' ),
'new_item_name' => __( 'New Topic Name' ),
'menu_name' => __( 'Topics' ),
);
// taxonomy register
register_taxonomy('topics',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'topic' ),
));
}

Reference : https://www.wpblog.com/create-custom-taxonomies-in-wordpress/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment