I'm new to Drupal and PHP. I've found many answers on stackexchange to the question of bulk adding fields to existing nodes. I need to add a field, like a tag or date (for future facet filtering), to existing nodes. I've been successful with creating a content type and setting up the default fields for users, but now we'd like to figure out how to do this if the nodes have already been created. The VBO module may be the best answer, however, we may have a few hundred of these nodes.

I see plenty of great example code, however, I am unsure of where to use this code. Do I do this on phpmyadmin? I'm more familiar with SQL, but I've read advice here that SQL should only be used if very familiar with Drupal. I'm using Drupal 7.

1 Answer 1


Fields are attached to Entities, not Nodes. So the field is either attached to bundle that is your node (for all nodes, pre-existing or not), or it hasnt been attached to that bundle yet.

You can use field_info_field and look at the element bundles to see if your given field is attached to the given Entity. If it isn't you can use field_create_instance to add the field to your entity.

You can get a list of all entity types and inspect their bundle types with the bundles key returned from entity_get_info by calling $site_entity_list = entity_get_info(NULL).

Entities and fields are cached, so be sure you use something like drush cc all to be sure you're looking at up-to-date values for all these function calls.

EDIT: You use these functions and PHP from essentially a small php script. Such business logic could be in a small module with hook_update_n() for instance. Or, you could use Drush and write a very simple PHP snippet using hte above 3 functions and some loops and call it using drush like: drush php-script your-script-filename.php

  • Thank you, tenken. I shall read your recommendations and try them out. Is Drush the best option? I definitely don't want to write a module. Have you tried devel or VBO ?
    – Don Struan
    Commented Nov 26, 2012 at 20:59

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.