Hi guys, I have to wrote to you because i'm becoming crazy, there are 2 days who I'm trying to add a taxonomy term to a node without luck.
Scenario:
I'm using a content type called: Place.
This content type own a field location (from location module) who has 2 values: street and city.
When a user compile these fields the GMap module make a google map with a marker.
When a node is saved i can access city and street using
print $node->field_place['und'][0]['city'];
print $node->field_place['und'][0]['street'];
What i want to do:
I will make a rule when a content is updated or saved, this rule have to add to my node a taxonomy term in the vocabulary cities with the value of
print $node->field_place['und'][0]['city'];
In this way every time a user create a new place with a new city, the city will be added to the vocabulary and assigned automatically to my node.
Now i'm stuck, (I've started with the update rule)
1: Event: After updating existing content
2 Conditions: Content is of type: Place
3 Actions: Fetch entity by id:
Entity type: Taxonomy Vocabulary
IDENTIFIER: 3 (my vocab ID)
4 Fetch entity by id:
Entity Type: Node
IDENTIFIER: node:nid
5 Create a new entity
Entity type: Taxonomy Term
Name: [node:title] (used only for testing purpose)
VOCABULARY: 3 (id of my cities vocabulary)
The rule works and add the taxonomy term in the right place, but...
1 Every time the view is updated the term will be cloned inside the vocabulary and this should not happen
2 My content type is not assigned to the term, if I go under any early term created I get this message: There is currently no content classified with this term.
Now my question is: What I should do to fix this? Someone could help me? For the old Drupal 6 I have found this script wich should do the trick via PHP in custom PHP:
Note: If you are putting the code into the "Custom PHP Code" section of a Triggered Rule in the Rules module, the same code would look like this:
$vid = 3; // The vocabulary ID for the taxonomy terms that you are interested in adding per the instructions above
$terms = array( 'Term1' , 'Term2' , 'Term3' , 'Term4');
// for example: $terms = array( 'Music' , 'CD' );
// Use a comma separated list
$node->taxonomy['tags'][$vid] = implode($terms, ',');
return array("node" => $node);This code looks to be easy to use i just need to add a variable and change the line
$city = $node->field_place['und'][0]['street'];
$terms = array( $city); But does not work with Drupal 7.
The full artiche can be found here
Thx a lot for help :)
Luke