最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - The Difference Between Categories and Tags and Taxonomies and Terms

programmeradmin3浏览0评论

I've got a custom post type 'articles' and I've added a custom taxonomy 'articles_categories' which has its own terms.

I was under the impression you can't have categories and tags on custom post types? But I can't see how Taxonomies and Terms are the same? And if you can have categories and tags on custom post types what is the reasoning for using custom Taxonomies? It's all very confusing.

Could someone explain the context of taxonomies and why can't you use categories and tags on custom post types?

Many thanks in advance

I've got a custom post type 'articles' and I've added a custom taxonomy 'articles_categories' which has its own terms.

I was under the impression you can't have categories and tags on custom post types? But I can't see how Taxonomies and Terms are the same? And if you can have categories and tags on custom post types what is the reasoning for using custom Taxonomies? It's all very confusing.

Could someone explain the context of taxonomies and why can't you use categories and tags on custom post types?

Many thanks in advance

Share Improve this question asked May 18, 2020 at 17:09 pjk_okpjk_ok 9082 gold badges15 silver badges36 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I was under the impression you can't have categories and tags on custom post types?

You can have categories and tags on custom post types!

But I can't see how Taxonomies and Terms are the same?

But they are the same, Categories are a taxonomy, as are post tags, they're stored in the database the same way as custom taxonomies, and use the same code and user interface.

The part that makes custom taxonomies "custom" is that it wasn't WP Core that registered them, it was you/a plugin.

Having said that, categories and tags have some legacy baggage that shows in certain file names, and some category/tag specific APIs. For the most part these can be ignored, and they have no bearing on custom taxonomies. Custom post types are in a very similar boat

And if you can have categories and tags on custom post types what is the reasoning for using custom Taxonomies? It's all very confusing.

There's a few reasons:

  • What if I want to show different categories of a product post type with just the products?
  • What if I want to list all categories next to posts, but some of those categories have nothing to do with posts because they're only used for a custom post type?
  • What if I want a taxonomy that is not a category or tag? E.g. country? Colour? Size?

A taxonomy is just a way to filter/group things together. Taxonomies have terms that are then used as boxes to group them together.

If you want to group X by Y, Y is a taxonomy, and X is a post type.

E.g. I want to group products by colour.

An example of a colour would be red, green, yellow, these are terms in the colour taxonomy.

Terms can be hierarchical, or non-hierarchical. E.g. Categories versus tags. I could extend the colour taxonomy example to say it is hierarchical, and that the yellow term has child terms for goldenrod or banana yellow.

So any time that you want to group posts by something, that's what taxonomies are for.

Also, anytime you need to filter/include/exclude posts by something, use a taxonomy. Some people store a post meta flag and then do a meta query, incurring a disastrous performance penalty. Just use a taxonomy instead, e.g. a show_on_homepage taxonomy with a yes and a no term, can be hundreds of times faster than a custom field.

发布评论

评论列表(0)

  1. 暂无评论