Relate all nodes from one taxonomy to another with MySQL

When using taxonomy to group nodes on your Drupal site, you find a need to apply another taxonomy term to all of those nodes (possibly from a different vocabulary) there is nothing that is going to be shorter and sweeter than some quick SQL-fu.

Here is a quick MySQL snippet to do just that:


create temporary table my_temp_table as
select * from term_node where tid = XXX;
insert into term_node (nid,tid) select nid, 'YYY' as tid from my_temp_table

Just replace XXX with the TID of the term that is already grouping your content, and replace YYY with the TID of the term you want to apply to all of them. You can comment out the first and last lines to use the select statement to check to make sure that these are the nodes you're after before committing all of the insert statements to the Database.

Enjoy!

Comments

does anyone know a way to build a related nodes link block not based on taxonomy, but on similarity in the node title?

Submitted by Guest (not verified) on Sat, 11/29/2008 - 03:46

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name