Adding terms in bulk with Views Bulk Operations

At some point in the evolution of your site, you may discover that you need to rework the organization of your content, such as through the introduction of a new set of categories. As part of this process, you will need to add the new categories to all your existing content. Luckily, the Views Bulk Operations (VBO) module makes it possible to add the term to nodes in bulk. (Note: As of Views Bulk Operations 7.x-3.3, there is a bug for any field using the autocomplete widget, where if you add a term that doesn’t exist yet and apply it to multiple nodes, a duplicate of the term will be created for each node you apply it to. This bug is discussed here: https://www.drupal.org/node/1507216. Until it is resolved, it’s best to add any new terms to the vocabulary first (by going to Structure > Taxonomy > [Vocabulary name] > Add term) before adding it to nodes using Views Bulk Operations.)

If the new categories for your site will be stored in a new vocabulary, create that vocabulary, as well as the term reference field pointing to the new vocabulary for the content types you want to update.

Install and enable the Views Bulk Operations module and create a view with a page display. The display format doesn’t matter, but the table format is often convenient. In the "Fields" section, in addition to "Content: Title" (or some other field that would uniquely identify individual nodes), add the field "Bulk operations: Content". Under "Selected bulk operations", check the box for "Modify entity values". That will open a section labeled "Operation settings", which lists a variety of general node properties (language, title, whether comments are allowed) before showing individual fields, grouped by the content type where they appear. Select the term reference field in question from the section corresponding to the content type you want to edit, then click "Apply". You can select more than one field or property here, and all will appear as options when you choose to modify the entity values.

Configuring a Bulk operations: Content field.

Configuring a Bulk operations: Content field. Check the box for "Modify entity values", then select the fields you want to be able to modify for multiple nodes at once. To illustrate, the "Tags" field has been added to the Image content type on the example site.

If there are hundreds of results, configure the filters on the view so you can narrow the results to only those where you want to apply the new taxonomy term. If you’ll be applying different terms to different sets of nodes, it may be convenient for you to create exposed filters so you can pull up different groups of nodes without having to edit the view. If the number of nodes you have to update is smaller, you can also select nodes individually from the list, instead of choosing the option to check the boxes for all nodes that appear in the view.

Save the view, and go to the page it created. If you have more than one page of results, you can choose to select all items on the current page, all items on all pages, or you can manually check boxes corresponding to individual nodes. At least one checkbox must be checked to proceed.

The page display of a view using Views Bulk Operations.

The page display of a view using Views Bulk Operations. Check at least one checkbox, select "Modify entity values", and then click "Execute".

Once you have checked at least one checkbox, use the dropdown under "Operations" to select "modify entity values", then hit "Execute". On the next page, you’ll see the selection widget corresponding to the term reference field you chose when configuring the view. If the field can accept more than one value, there’s also a checkbox for appending the new value(s) you select here to the node’s existing values; the default behavior is to overwrite (delete) the old value.

Selecting the taxonomy term "Midwives" to apply to all selected Image nodes in the "Tags" field. Due to a bug with the autocomplete widget used by Views Bulk Operations, be sure to add the terms to the vocabulary first, before trying to assign them to nodes.

Once you have made the selection, hit "Next", confirm, and Views Bulk Operations will make the changes.

VBO can also be used to modify node properties besides term reference fields, and is often more efficient for doing things like publishing or unpublishing nodes than using the content management interface (available by clicking on Content) because you can process more than one page of results at a time.

A word of caution, however: a view that has a bulk operations field gets the same default access restrictions as any other view, which is to say, it is viewable by any user with the permission to see published content. This generally includes unauthenticated users. Because VBO allows you to make administrative-type changes to nodes, it is best to change the permissions for views that include a VBO field to restrict it by role, and only grant access to admins and other trusted users.