1

So for the past week or so, I've been developing a plugin that lets users manage a restaurant menu. I've learned a lot about the process of making plugins as far as adding custom post types, creating posts, customizing the admin menu, getting posts, etc. I am still stuck on terms and taxonomies and what exactly they are.

Previously, I developed this menu plugin by making custom post types for menus(breakfast, lunch, dinner, etc), categories(Appetizers, Entrees, etc), and dishes. Every time a dish was added, it would have a post_parent of the category it was under. The categories would have a post_parent of the menu they were under.

Now I am wondering... would it be better to do this by using terms and taxonomies? Or do I have the complete wrong idea about them?

1
  • If you mean default Wordpress categories then note that these are basically same as taxonomy (so are tags), it's just built-in to Wordpress by default. I usually leave categories and tags alone and only use them in blog and declare my own custom taxonomy for my custom stuff. Custom posts are your main things that has all the content if that makes sense and taxonomies are used to group them. Apple pie (custom post) => dessert (taxonomy), lunch (taxonomy). Taxonomies can be used for a lot of things like making navigation easier for user, showing features.. Imagination is the limit.
    – N00b
    Commented Jan 16, 2016 at 1:45

1 Answer 1

2

Posts are things

Taxonomies and terms are types or classifications of things

E.g. I could have a post type animal, with animals such as "Betsy", "Rover", and "Mittens". I can then have a taxonomy called species, that contains terms such as cat, dog, budgie. I can then assign the "Mittens" post to the cat term in the species taxonomy.

The important part here is that all the content is inside posts. Taxonomies and terms provide means to group or classify the content, but they aren't content themselves

A good heuristic is that you filter and group posts using taxonomies. In this case Menus sounds like a taxonomy, and breakfast/lunch/dinner/etc sound like terms in that taxonomy. The same for categories. Finally, a post of type dish

Interesting Facts

  • Categorys are a taxonomy, individual categories are terms in the category taxonomy
  • Tags are also a taxonomy, the difference being that they are of the taxonomy tag and that the tag taxonomy is non-hierarchical ( no parent or child tags )
  • Some taxonomies do not have a UI and are hidden from the user
  • Nav menus are actually terms. The menu items are posts of type nav_menu, and they'd held together by a shared taxonomy term. Creating a new menu creates a new term. This is all done behind the scenes
  • Taxonomies have their own archive pages and templates, refer to the template hierarchy flow chart to see what templates are available to you
  • Taxonomy relationships appear to be between terms and posts, but they're actually between terms and IDs. These don't have to be post IDs, they can be user IDs too. There are articles about creating user taxonomies for things such as jobs and departments etc
  • I would recommend that you use the taxonomy and term APIs exclusively, and ignore the tag and category specific APIs. The category/tag functions use them internally, so it should simplify your work as the same code can be used for all taxonomies, and you'll have a better understanding of how things work
3
  • So is it possible to make one taxonomy the parent or child of another taxonomy? Like if I had a menu called breakfast and a category called Eggs & Omelelttes, could I make the Breakfast menu the parent of Eggs & Omelettes? Commented Jan 16, 2016 at 2:31
  • That makes no sense, in the same way that a colour taxonomy being the parent of a shape taxonomy is a weird thing to say that'll get you funny looks, why would the colour red be a parent of cylinders and cones? It's a silly sentence. Taxonomies and terms classify things. You can have hierarchy inside a taxonomy, but hierarchy between taxonomy terms is nonsensical. Perhaps you're confusing UI/Theming/URLs with data structure?
    – Tom J Nowell
    Commented Jan 16, 2016 at 3:40
  • Also, in the answer I proposed, Eggs and omelettes would be a dish, a post of type dish, whereas breakfast is not a post. A posts parent must be another post. In the same way that a blog post cannot be a child of a category or a tag, that makes no sense. The post is in that category, not a child of it, and it can be in multiple categories. Categories are not things or objects, but Posts are. Again to stress, taxonomy terms are not posts.
    – Tom J Nowell
    Commented Jan 16, 2016 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.