2

I am writing a module that creates a vocabulary through code. Here's what I use:

$new_vocab_name = 'my_categories';
$vocab_obj = (object) array(
   'name' => t('My Categories'),
   'machine_name' => $new_vocab_name,
);
taxonomy_vocabulary_save($vocab_obj);

How do I add custom fields for terms that will be in this vocabulary? E.g., I want to add an image field for each term.

1

I think this article will be usefull for You because taxonomy is one of entity types: Working programmatically with fields in Drupal 7

So You should set "entity_types" as taxonomy.

2
  • 1
    Thanks; to be more precise, the entity_type must be set to taxonomy_term, and in order to get a list of available entities, you can use the function entity_get_info().
    – Yusuf
    Aug 16 '12 at 10:13
  • I'm also linking to this post because I was having some trouble using the custom field and it helped me sort it out.
    – Yusuf
    Aug 16 '12 at 12:16

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.