Is it possible to automatically add a new taxonomy term (related to certain vocabulary) from a field in a custom content type; so when submitting a new content entry (related to that custom content type) I add a new taxonomy term related to that entry to create a richer tagging functionality by time for future entries?
-
Add a new taxonomy to what ?– tostinniJun 10, 2011 at 18:52
-
The question is ambiguous. Can you please be more specific?– Adam SJun 10, 2011 at 18:52
-
@tostinni: to a taxonomy vocabulary that already exists.– wassimansJun 10, 2011 at 18:55
-
Could you give an example?– Karl JóhannJun 12, 2011 at 10:43
1 Answer
Check out taxonomy_save_term(). Here's an example from the comments:
$term = array(
'vid' => 5, // Voacabulary ID
'name' => 'Drupal', // Term Name
'synonyms' => 'Druplet', // (Optional) Synonym of this term
'parent' => 11, // (Optional) Term ID of a parent term
'relations' => array(15), // (Optional) Related Term IDs
);
taxonomy_save_term($term);
You could use this inside hook_nodeapi() on the operations insert
or presave
(and update
). See the comments at the first link for more info.
EDIT: For drupal 7 you have to check out the node api instead of of hook_nodeapi().
-
-
Actually I found this for Drupal 7: api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/…. Thanks for the tip. Jun 10, 2011 at 20:09