Add taxonomy with custom fields programmatically

Taxonomies are very useful in Drupal when you need to organize your content but sometimes the default and available fields are not enough. Here is an example how you can add some to you taxonomy vocabulary.

If you want to create a taxonomy from a PHP script, here is what you could do:

taxonomy_vocabulary_save

Some fields examples ($array_fields)

Some instances examples ($array_instances)

 

To load the taxonomy vocabulary when it is created:

taxonomy_vocabulary_machine_name_load

7 Thoughts on “Add taxonomy with custom fields programmatically

  1. khaled on March 27, 2015 at 14:24 said:

    Hi,

    This code add field’s to vocabulary itself or it’s terms?

  2. kim paolo landicho on June 1, 2015 at 01:51 said:

    Thanks this works :)

    At first it has error because of typo

    foreach ($array_fields) as $field) {
    field_create_field($field);
    }

    just remove the ) it and it will work fine.. thanks again :)

  3. Thank you so much , you saved my time

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation