1cliiq
Last Updated: February 15, 2018
·
48
· Moeez

Create Custom Taxonomies In WordPress

Taxonomies groups your content into specific categories. For example, you have tutorials on WordPress, WooCommerce and Drupal on your website. You can group them into topics like:

WordPress Tutorials
WooCommerce Tutorials
Drupal Tutorials

Creating a taxonomy on a WordPress website is easy. Just use the code below in your functions.php file and you are good to go:

addaction( 'init', 'createcwhierarchicaltaxonomy', 0 );
//create a custom taxonomy name
function createcwhierarchicaltaxonomy() {
$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
itemcolon' => _( 'Parent Topic:' ),
'edititem' => _( 'Edit Topic' ),
'updateitem' => _( 'Update Topic' ),
'addnewitem' => _( 'Add New Topic' ),
'new
itemname' => _( 'New Topic Name' ),
'menuname' => _( 'Topics' ),
);
// taxonomy register
registertaxonomy('topics',array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show
ui' => true,
'showadmincolumn' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'topic' ),
));
}

I used the following reference articles to find the code. You can view the full guide from here as well.

https://www.wpblog.com/create-custom-taxonomies-in-wordpress/
http://www.wpbeginner.com/wp-tutorials/create-custom-taxonomies-wordpress/