How To Get Custom Taxonomy Term Link In WordPress Archive Pages

How To Create Custom Taxonomy In WordPress

WordPress allows you to organize your posts in categories and tags. By default WordPress has three built-in taxonomies:

  • Category: It allows you to group your posts together by sorting them into various categories.
  • Tag: Tags allows you to group your posts together in a freeform. Tags can be made by simply typing them.
  • Link Category: Link category let you categorize your links. Nothing special about them.
  • Navigation Menu: The taxonomy we use to manage your navigation menus.

WordPress’ custom taxonomy feature allows you to create your own custom category or tag style taxonomies to manage your posts and extend your WordPress. You can create your own Wikipedia or IMDb.

For an example, IMDb categorizes movies on their website within various taxonomies, such as Directors, Writers, Actors & more.

Create Custom Taxonomy

Now we will show you to easily create custom taxonomy and assign them to your posts or custom post types.

[alert style=”green”]Easy Way Out: You can also simply generate Custom Taxonomy with generatewp.[/alert]

First we will start our custom taxonomy plugin by adding following header to the plugin file:

We will create a custom taxonomy for teams. Before the closing PHP command, add the following action to our plugin:

Now, we will register and add elements to our taxonomy with following code:

In the first part of our code, we have entered the taxonomy name and all other basic stuff. Nothing special to learn here. Just replace Team word with your taxonomy name.

Second part of the code contains all the configuration about our taxonomy.

  • ‘hierarchical’ => true determines the structure of our taxonomy. Categories have the hierarchical structure, while the tags have a non-hierarchical structure.
  • ‘public’ => true determines the visibility of our taxonomy both in front and back-end.
  • ‘show_ui’ => true determines whether to show taxonomy in the admin menu.
  • ‘show_admin_column’ => true determines whether to show taxonomy columns on associated post-types.
  • ‘show_in_nav_menus’ => true determines whether to make our taxonomy available for selection in Navigation Menus.
  • ‘show_tagcloud’ => true determines whether to show in tag cloud widget.

The last line of your code assigns our taxonomy to post types.

Save your plugin file. Now, just upload and activate this plugin to get started with your new custom taxonomy. You can create or edit your posts to play with your new taxonomy. Don’t forget to leave a comment if you have any questions.