I would like to know how I can add attributes to taxonomies and allow those attributes to have different values in different posts.

For example, let's say I have a recipe custom post type and I have ingredients as a taxonomy. The amount of each ingredient to use could be different for different recipes.

So how would I implement such attributes into WordPress in a way that maintains my data integrity and also allows me to insert the attribute values from the post creation page?

Please note that this is only an example, I'm asking about this concept in general.

  • 1
    It sounds like custom meta would be better than taxonomies for this. Can you tell my why you have decided on taxonomies? – s_ha_dum Apr 29 '15 at 19:22
  • I think that the concept is wrong. Think about it. The "Quantity" would be a attribute of the recipe, not of the ingredient. I would use a meta field for that, maybe the ingredients taxonomy also to group recipes by ingredient, but I would keep the quantity of ingredientes as custom meta field of the recipe, not as a attribute of the ingredients. – cybmeta Apr 29 '15 at 19:23
  • @s_ha_dum I chose taxonomies because I can organize and filter recipes using ingredients, the quantity relates to both that's why I asked the question the way I did. But can you explain how I would use custom meta fields instead? Sorry I'm new to WordPress – user4181107 Apr 29 '15 at 20:28
  • You can organize and filter by meta field too. Try to search the site for "custom meta field" and see if you can get started. – s_ha_dum Apr 29 '15 at 20:30
  • @s_ha_dum Also, don't custom fields add extra fields to the post database table? If there is an unknown number of ingredients to be used, adding a custom field to store the amount of each ingredient would make the number of fields added unknown, isn't that a problem? – user4181107 Apr 30 '15 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.