• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
WPFeed

WPFeed

  • News
  • Tutorials
    • WordPress Multisite
    • BuddyPress
    • Design
  • Reviews
    • Plugins
  • Roundups
  • Snippets
  • Giveaways
Home » How To » Creating Your First Custom Taxonomy in WordPress

Creating Your First Custom Taxonomy in WordPress

custom-taxonomy

Tag and category are two default WordPress taxonomies. They help to manage and grouping your WordPress posts. However, sometimes that isn’t enough, especially when you have Custom Post Type. For example, if you have Portfolio CPT, having ‘Type’ or ‘Price Range’ taxonomy will help you grouping all the portfolio items differently from normal posts. For more information about Custom Taxonomy, WordPress Codex is one of the main resources you should refer to.

Create a Custom Taxonomy

In this example, I’m creating Type custom taxonomy and assign it to Portfolio CPT. You may copy and paste the snippet below to your functionality plugin. This custom taxonomy helps me to group or classify my portfolio based on the type of the project I’ve done.

The code might look complicated at first but it’s not. Here are some important parameters that you should know:

'name' – This is the name of you custom taxonomy. If you wish to create a custom taxonomy other than ‘Type’, simply change your taxonomy name here. Moreover, don’t forget to change the word ‘Type’ or ‘Types’ from line 8 to 22.

'show_in_nav_menus' – If you want to display your custom taxonomy, this should be set to true.

'hierarchical' – Setting this to true will make your custom taxonomy behaves like Category while setting it to false will make your custom taxonomy behaves like Tag.

register_taxonomy( 'types', array('Portfolio'), $args ); – In line 38, this is where I assigned this custom taxonomy to my Portfolio CPT. If you want to assign it to multiple post types, you may do so by using a comman. Example: register_taxonomy( 'types', array('Post, Portfolio, Gallery'), $args );

It’s important to know that the code above does not include all parameters that can be accepted by the register_taxonomy functions. For complete list of all parameters, please refer Parameters – register_taxonomy page on WordPress Codex.

Making Life Easier with Custom Taxonomy Generator

If you build lots of sites for clients, you’ll eventually notice that you can simply reuse the code over and over again with only some minor modifications. That’s the reason why custom taxonomy generator is very useful and becomes very handy.

One of the great tools  available is WordPress Custom Taxonomy Code Generator by Themergency.

Believe it or not, the code I’ve just presented above is generated by this tool. It rocks and is very handy.

We hope this tutorial helped you to create your first taxonomy and if you’ve any question, feel free to leave your question in the comment section below.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • WordPress is a brilliant platform that is loaded with tons of stuff for websites.
  • How to Sync Stock & Price for WooCommerce Products
  • How to migrate a WooCommerce Store to a new site
  • How to Import WooCommerce Products
  • How to export WooCommerce Orders

Copyright © 2023 · WPFeed.com - A Project of TechAbout LLC.

  • About us
  • Advertise
  • Write for us
  • Terms and Conditions
  • Privacy Policy
  • Contact us