2

I need to copy the title of nodes to its taxonomy term. I have the following content type

  • Title - text
  • Body - text
  • Taxonomy term - (currently empty)

I want to copy the "Title" ---> "Taxonomy term" for each node.
How can I do this?

I understand that VBO with som php-snippet could solve this but I am no programmer. Any suggestions about a working snippet or other solution?

1 Answer 1

1

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.

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.