[support] Inserting a new taxonomy and adding a node in this taxonomy

Carlos Rincón crincon at neuroticweb.com
Mon Feb 26 16:02:45 UTC 2007


El lun, 26-02-2007 a las 07:52 -0800, Marc Poris escribió:
> Carlos,

Hi Marc,

> 
> To insert the new taxonomy term you'll probably want to call 
> taxonomy_save_term(&$form_values) which is what gets called when 
> submitting the taxonomy term form.  You'll need to fake the form_values 
> data, and you won't want to provide a tid so that one gets generated for 
> you.
> 
> To have your node appear within the term, you can probably call 
> taxonomy_node_save($nid, $terms) or fill in $node->taxonomy if you know 
> that your hook_nodeapi will be called before taxonomy's hook_nodeapi 
> (you can set the weight of your module to be lower than taxonomy's)...
> 
> I hope that gives you somewhere to start,
> 
> Marc

Thanks for the tip, but I solved this a few days ago, i wrote how in
drupal.org http://drupal.org/node/120830


> 
> 
> Carlos Rincón wrote:
> > Hi all,
> >
> > i need to add in the fly a taxonomy to a book. I've put an extra field
> > in my book (a cck node) in case the user want to add a new taxonomy
> > without going to the form taxonomy.
> >
> > I've a custom module to handle this:
> >
> > function source_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
> > 	switch ($op) {
> > 		case 'submit':
> > 			if ($node->type == 'content_libro') {
> > 				echo "Nuevo Autor: " . $node->field_nuevo_autor[0]["value"];
> > 			}
> > 			break;
> > 		case 'insert':
> > 			break;
> > 		case 'update':
> > 			if ($node->type == 'content_libro') {
> > 				echo "Nuevo Autor: " . $node->field_nuevo_autor[0]["value"];
> > 			}
> > 			break;
> > 		case 'view':
> > 			break;
> > 	}
> > }
> >
> > (This is from drupal.org)
> >
> > Now i need to create the taxonomy and then to put the book node in this
> > taxonomy. I suppose it can be done with taxonomy_nodeapi o something
> > similar but i'm newby in Drupal.
> >
> > thanks in advance,
> >   
> 
> 
-- 
Carlos Rincón
www.neuroticweb.com
www.neuroticweb.com/blog



More information about the support mailing list