3

I am trying to programatically add some tags to a node's free tagging taxonomy field. Assuming that 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);

?>
obada
  • 181
  • 3
  • 13
  • check out this post: http://stackoverflow.com/questions/4985779/drupal-7-insert-taxonomy-into-node-object?rq=1 – FLY Jun 19 '12 at 09:37

1 Answers1

0

You shouldn't need to do this programatically, in Drupal 7. Just add a taxonomy term field to your content type using widget type "autocomplete" - then click on "edit" and select default tags.

You are done, unless you want to hide the field from the content entry form (which is a separate issue, answered here: How to hide a field on node data entry form in drupal? )

Screen Shot of Default Tags

Community
  • 1
  • 1
Jennifer B
  • 51
  • 2
  • 1
    yes, I do need to do it programatically. and the reason I am doing this is because I am creating a custom import module to import my drupal 5 content to drupal 7. – obada May 20 '12 at 05:59