For example:
I have vocabularies "colors" and "size". I wish to remove all terms set on a node in the "colors" vocabulary.

I needed to do something like this and was amazed that I couldn't find a solution. I wrote some php to handle this and thought I would share it in case anyone else needs this functionality in the future:

function remove_all_terms($node, $old_term_array){
foreach($old_term_array as $key){
$node = rules_action_taxonomy_term_remove_from_content($node, $key, $settings);}
return $node;
}
$vid = $taxonomy_vocab->vid;
$oldterms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
$old_term_array = $oldterms;
$node = remove_all_terms($node, $old_term_array);
return array("node" => $node[node]);

This code assumes you have loaded the vocabulary you wish to target and that it is saved in the variable taxonomy_vocab. It also assumes you have implemented the "remove term" fix which is posted to http://drupal.org/node/577826 but has not been committed to any build.

This code can simply be dumped into an "execute custom php code" action which follows the load vocabulary in linear order.

Hope this is useful to someone!

Comments

melchoir55’s picture

Component: Rules Core » Rules Engine

Users should note that if there is nothing set in the vocabulary identified by $taxonomy_vocab, then this code will return an error because that last line will have an empty variable $node[node]. This doesn't matter for me because my vocabs are autoset at node creation, but if you need to deal with this then you could probably just drop the last line in a wrapper like

if ($node[node]){
return array("node" => $node[node]);
}

untested but it gives you an idea.

mitchell’s picture

Status: Active » Closed (fixed)