I created some fields such as Color called field_color (taxonomy terms) in the product content type but whatever I do, when I create a product and set the field_color, the color name doesn't show up on the product page. I also tried to create fields programmatically with hook_install and hook_schema_alter but to no avail. Maybe I'm doing something wrong as I have never created any fields/schema before.

  • Is field_color a term reference field? and does your taxonomy vocabulary exist and have terms in it? – Ollie Jul 2 '14 at 10:35

Here's how you create a term reference field to a CONTENT_TYPE:

  1. Create a taxonomy vocabulary called, say, "Color" at admin/structure/taxonomy/add.
  2. On admin/structure/taxonomy, click "add term" next to your new vocabulary.
  3. Add terms, such as, say, "blue", "red", etc.
  4. Go to /admin/structure/types/manage/CONTENT_TYPE/fields
  5. Add a new field called, say, "Color", and, set its "field type" to "term reference". Select an appropriate widget, such as "select list".
  6. Go to /admin/structure/types/manage/CONTENT_TYPE/display and set the field's display to, say, "link". You can try different display options, such as "plain text" too.

Hope that helps.


To create a node and save this field programmatically, follow this example, which has instructions for saving term reference fields.

| improve this answer | |
  • field_color is a term reference field but whenever I try to create programmatically a product and do something like $newnode->field_color[0]['value'] = $color; it doesn't show up on the product page. – Jiang Jul 2 '14 at 12:54
  • That's because you need something like: $newnode->field_color[LANGUAGE_NONE][]['tid'] = $tid; (where $tid is the ID of your term) – Ollie Jul 2 '14 at 13:08

Your Answer

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

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