How To Display Different WordPress Metabox Based On Your Taxonomy

On 5 Jun, 2014 By With 0 Comments

Ever since WordPress introduced Custom Post Types and Taxonomy, a different door was open, developers can push the limits of WordPress and creating a theme for different niche becomes easy. Real Estate and Movie Themes came out, and a bunch of others that uses the power of Custom Post Types.

And since we are utilizing the power of Custom Post Types and Taxonomy, displaying them is really a different story. Once of my Client asked me to display two different taxonomy using single.php, since they uses that page to display different things.

Today, I’ll share with you on How To Display Different WordPress Metabox Based On Your Taxonomy, mostly on single.php but you can still using this on page.php or other WordPress Files.

90H How To Display Different Wordpress Metabox Based On Your Taxonomy

Display Different WordPress Metabox Based On Your Taxonomy

I’ll assume you already know how to build a metabox, if not here’s a list of metabox tutorials and plugins on how to do so. Same with Custom Post Types, you can check out these tutorials on how to do it.

We will utilize the has_term, you can check it out from the codex, here’s a short explanation: Check if the current post has any of the given terms.

On your single.php, under the_content hook we want to display our metabox.

 Band is our term and blog_cats is our taxonomy, we will display our metabox according to the term of the taxonomy.

The code above displays different information about the Band, the Client wanted to designed it this way because they are using this part as a sidebar.

You can use this if you have several taxonomy term and you wanted to display different metabox or information about it and you’re using single.php or page.php. I find it really easy to display different information and it saves me a lot of time by not creating another page template.

Hope this is helpful to you, if you have any suggestions to push this further please do so in the comments below. If you have any request, please let me know!

Leave a Reply