Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save algotrader-dotcom/0d67b73cf10a4d4838f9 to your computer and use it in GitHub Desktop.

Select an option

Save algotrader-dotcom/0d67b73cf10a4d4838f9 to your computer and use it in GitHub Desktop.
Drupal 7 : Update taxonomy term programmatically
<?php
define('DRUPAL_ROOT', '/home/vhosts/domain.com');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once( DRUPAL_ROOT . '/sites/all/libraries/simplehtmldom/simple_html_dom.php');
include("phpcrawler/libs/PHPCrawler.class.php");
set_time_limit(0);
$vid = 10; // Category
if ($terms = taxonomy_get_tree($vid)) {
foreach ($terms as $term) {
if ($term->tid == 61440){ // Working with term 61440
$term_name = $new_value;
$new_term = taxonomy_term_load($term->tid);
$new_term->name = $term_name;
print_r($new_term);
taxonomy_term_save($new_term);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment