You could use a combination of the Rules module and the VBO module to create a custom rule component, which you then use as a custom VBO action.
For way more details on this combination, have a look at my answer to "How to bulk update select list fields?".
In your case, the custom Rules Component should look pretty similar to this:
{ "rules_set_an_initial_value_for_a_term_field" : {
"LABEL" : "Set an initial value for a term field",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_yourfield" } }
],
"DO" : [
{ "data_set" : { "data" : [ "node:field-yourfield" ], "value" : "HereGoesTheTitle" } }
]
}
}
Some more details to further explain the above example:
- adapt the machinename of
field_yourfield
to the machine name for your taxonomy term field.
- replace the (hardcoded)
HereGoesTheTitle
value in the Rules Action by the token like node:title
(which for sure wil be available).
- I'm assuming your taxonomy term is a single value field, if it is a multi value field, then replace the action with a similar one to "Add an item to a list" (related to your multi value field).
PS: no need at all for any custom PHP code when using this approach.