Copy taxonomy terms from one node to another
Particularly un-clever code:
function wsf_action_copy_terms($from_nid, $to_nid) {
// can you spell optimizable? Neither can we.
// this whole thing could be done with a single mysql query probably
// but would that be the Drupal way?
// probably would've been better to rip out the guts here... http://api.drupal.org/api/function/taxonomy_node_get_terms/5
$terms = taxonomy_node_get_terms($from_nid);
// slower but more specific if it ever matters: $terms = taxonomy_node_get_terms_by_vocabulary($from_nid, place_taxonomy_get_vid());
// adapted from http://api.drupal.org/api/function/taxonomy_node_save/5
// WARNING: INSERT IGNORE is MySQL only
foreach ($terms as $tid => $term) {
db_query('INSERT IGNORE INTO {term_node} (nid, tid) VALUES (%d, %d)', $to_nid, $tid);
}
}
For more, see:
http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html
Resolution
More like this
- Copy (or inherit) taxonomy terms from one node to another
- Taxonomy_term_count_nodes gives stupid results when child terms have same nodes
- Exclude the results of a one-node view from another view (the Featured Feature problem)
- List taxonomy terms that belong to nodes that belong to another taxonomy term
- taxonomy_term_count_nodes() flakes out: empty white screen when term has itself as parent


Comments
Post new comment