I’m implementing various custom taxonomies for my project and I came across the concept of custom fields for custom taxonomies, which baffles me. I though custom fields where just custom fields associated to posts and not a taxonomy. Can someone explain this relationship and how it is used? Thanks!
Leave a Reply
You must be logged in to post a comment.
Custom fields for custom taxonomies are nothing more than custom templates. For example, you can remove the template of the
post_tag
taxonomy viaremove_meta_box()
function and add custom template viaadd_meta_box()
function.Examples
Remove tags template:
The above removes the Tags box. We’ll add it again, but we’ll change the template of the
post_tag
taxonomy. In this case we’ll remove the input bar where people used to type in their new tag terms, in our new template, people can only choose predefined tags from a dropdown list.The template:
As you can see in the code above, the custom
post_tag
template is ready and we only need to hook it into WordPress, the code below will do that job.As you can see in the above examples, you can modify the default templates of built-in meta boxes, you can even remove the post excerpt meta box and reattach again to enable WYSIWYG support.
The above code is not the best example and I’ve written the functions on the fly, but I’ve used this functionality few times when I wanted clients to choose where they want to put their content on the front page; e.g. slideshow area, features area, etc…
Cheers,