User login

Update Taxonomy Terms code snippet

/* drupal taxonomy term conversion script by Agaric Design /
/
In some cases an older vocabulary may be replaced with a newer vocabulary. This script can help you replace terms from the older vocabulary with terms from the newer vocabulary. You'll have to create the association yourself, and put it in the form of an array as shown. /
/
keywords: convert category categories database vocab vocabulary terms
change taxonomy term tid
this might also be useful for splitting or merging vocabularies */

// Category - Old Taxonomy tid - New Taxonomy tid

// // Category name
// old => new,

$taxonomy_change = array(

// newsletter issue
// -- 2006-01
53 => 73,

// -- 2006-03
50 => 72,

// -- 2006-05
52 => 71,

// -- 2006-06
49 => 70,

// -- 2006-07
48 => 69,

// -- 2006-08
47 => 68,

// -- 2006-09
46 => 67,

// -- 2006-10
45 => 66,

// 2006-11
51 => 65,

// Newsletter Section
//-- Editor's Note
59 => 74,

// -- News
61 => 75,

// -- Other News
60 => 76,

// -- Event
43 => 77,

// -- Featured Article
37 => 78,

// -- Featured Org
41 => 79,

// -- Interview edit
40 => 80,

// -- Tips
42 => 81
);

foreach ($taxonomy_change as $old_tid => $new_tid)
{
$query = 'UPDATE {term_node} SET tid=' . $new_tid . ' WHERE tid=' . $old_tid;
$result = db_query($query);
if ($result) echo "Successful: $query
\n";
else echo "Failed: $query
\n";
// echo "Test: $query
\n";
}

/* drupal taxonomy term conversion script by Agaric Design /
/
In some cases an older vocabulary may be replaced with a newer vocabulary. This script can help you replace terms from the older vocabulary with terms from the newer vocabulary. You'll have to create the association yourself, and put it in the form of an array as shown. /
/
keywords: convert category categories database vocab vocabulary terms
change taxonomy term tid
this might also be useful for splitting or merging vocabularies */

// Category - Old Taxonomy tid - New Taxonomy tid

// // Category name
// old => new,

$taxonomy_change = array(

// newsletter issue
// -- 2006-01
53 => 73,

// -- 2006-03
50 => 72,

// -- 2006-05
52 => 71,

// -- 2006-06
49 => 70,

// -- 2006-07
48 => 69,

// -- 2006-08
47 => 68,

// -- 2006-09
46 => 67,

// -- 2006-10
45 => 66,

// 2006-11
51 => 65,

// Newsletter Section
//-- Editor's Note
59 => 74,

// -- News
61 => 75,

// -- Other News
60 => 76,

// -- Event
43 => 77,

// -- Featured Article
37 => 78,

// -- Featured Org
41 => 79,

// -- Interview edit
40 => 80,

// -- Tips
42 => 81
);

foreach ($taxonomy_change as $old_tid => $new_tid)
{
$query = 'UPDATE {term_node} SET tid=' . $new_tid . ' WHERE tid=' . $old_tid;
$result = db_query($query);
if ($result) echo "Successful: $query
\n";
else echo "Failed: $query
\n";
// echo "Test: $query
\n";
}

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.