Next, we need to test our new rendering code. Does it work on each of the pages and only for those that have terms? Let’s test it together. Here is the department taxonomy term rendered into the entry footer of a post: Here it is for a team bio single: Then we need to commit our work to GitHub to save it. Let’s do that together.
To better understand how you get the taxonomies, let’s go look in WordPress Core. You’ll look at get_taxonomies() which is in wp-includes/taxonomy.php. You’ll discover that this construct is merely using the global variable $wp_taxonomies and filtering what you want to view.
Did you know that you can use a template to target a specific taxonomy? And you can target a specific term too. WordPress lets you drill down and build specific user experiences even at the taxonomy and term level. Let’s talk about that.
Way to go! You just built a new feature into your Team Bios plugin. You learned how easy it is to configure and register custom taxonomy. You learned how to bind it to multiple post types. You even got a couple of lessons in PHP string building. Whew, you did it! Now let’s push your new plugin up to your GitHub repository. We will continue building this plugin in other labs including adding custom fields (metadata) and meta boxes to it for team attributes like title, social media links, etc. Get it on GitHub
You learned in the Custom Post Type Basics lab that you need to flush the rewrite rules when registering a custom post type. You need to do it for a custom taxonomy too. Remember, never ever ever do it after you register. Listen to me. It’s too expensive and will slow down your website. The proper way is to do it when the plugin is activated. In this episode, let’s add our taxonomy registration function to the plugin’s activation handler. Then we’ll deactivate and test. Let me show what it does. Next, let’s add the handler for when a plugin […]
Let’s walk through the rest of the configuration arguments available from WordPress. We’ll turn them on and off to see what they do. You’ll also discover just how easy it is to add the terms to the post type’s table in the backend.
So far you’ve bound the custom taxonomy to just one post type, i.e. our “team-bios” custom post type. But what if you want to assign it to multiple post types? For example, what if your client wants to assign departments for some of their blog posts? Think about it. Maybe they will write news and press releases and they want to group it by the department. In this episode, let’s assign our new custom taxonomy to both the “team-bios” and “post” post types. We’ll also talk about interfaces and what’s really going on. The back-end is just an interface that […]
In the last episode, you and I registered a custom taxonomy with the minimum configuration. But look at the taxonomy interface in the back-end. What do you see? The top of the page says “Departments” but the rest of the interface says “Category.” Hum, do you think that will confuse your customer? Yes, it will. One of our jobs as a WordPress developer is to make the interface as easy to use as possible. That means we need to make sure the labels are right, instructions are clear, and the entire interface is clear and self-supporting. You don’t want them […]
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: 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. In this episode, you’ll walk through […]
In this episode, you will learn about what makes a taxonomy a custom one. We’ll discuss the what (what is it), why (why you want to use it), and when (when you want to use it versus the built-in taxonomies).