Drupal 7 - programmatically add free tagging to Node

I am trying to programmatically add tags to the taxonomy field of a free node tag. Assuming I have the following node structure,

<?php

$my_tag = 'test';

$node = (object) array(
  'type' => $node_type,
  'nid' => $row->nid,
  'vid' => $row->vid,
  'uid' => 1,
  'status' => $row->status,
  'language' => $row->language,
  'created' => $row->created,
  'changed' => $row->changed,
  'comment' => $row->comment,
  'promote' => $row->promote,
  'title' => $row->title,
  'teaser' => $row->teaser,
  'field_custom_tags' => //TODO add $my_tag to this free tagging taxonomy field
);

$node = node_submit($node);
node_save($node);

?>
+3
source share
1 answer

You do not need to do this programmatically, in Drupal 7. Just add the termonomy term field to your content type using the “autocomplete” widget type - then click “edit” and select the default tags.

You have finished if you do not want to hide the field from the content entry form (which is a separate problem that was answered here: How to hide the entry form of the node form in drupal? )

Screen Shot of Default Tags

0
source

All Articles