Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
Registering a Custom Taxonomy
Lab: WordPress Custom Taxonomy Basics
Video Runtime: 09:54
Let’s register our custom WordPress taxonomy. We are going to call it “department” as we need to group our team biographies by departments. You will be amazed at how easy it is to register a custom taxonomy. Seriously. A couple lines of code and Bam, it’s done.
Here’s the code for the bare minimum configuration requirements:
$args = array( | |
'label' => __( 'Departments', 'teambios' ), | |
'hierarchical' => true, | |
); | |
register_taxonomy( 'department', 'team-bios', $args ); |
You register a callback to the init
event (see the full code file below). Then it’s a couple lines of code to configure the taxonomy. Notice that this one is configured as hierarchical, just like the built-in categories.
-
Want to see the entire taxonomy.php file? Click here
In this episode, you’ll walk through the process of adding a new file into the plugin, autoloading it, and configuring the bare minimum needed to add in the department taxonomy. We’ll talk about PHP namespacing too as I’ll break the site and then walk through why it broke.
You don't need a 3rd party plugin to add a #WordPress taxonomy. It's a couple lines of code Share on XHere is the link to register_taxonomy()
in the WordPress Codex.
Code. Eat. Code. Sleep. Dream about Code. Code.
Episodes
Total Lab Runtime: 01:30:53
- 1 Lab Introductionfree 08:15
- 2 Custom Taxonomy - The What, Why, and Whenfree 08:32
- 3 Registering a Custom Taxonomypro 09:54
- 4 Configure the Labelspro 14:51
- 5 Bind to Post Typespro 11:55
- 6 Configuring Argumentspro 07:52
- 7 Render Entry Footer Termspro 08:40
- 8 PHP 101: Concatenating Assignment Operatorpro 02:26
- 9 PHP 101: Building Stringspro 08:19
- 10 Test Entry Footer Termspro 03:03
- 11 Flush Rewrite Rulespro 03:56
- 12 Wrap it Uppro 03:10