Create Taxonomies Programmaticallly


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function updateCategory($vid, $term) {
  2.  
  3. // Make sure the database has all the entries
  4. $parent = 0;
  5.  
  6. // Is there an ID for this term already?
  7. $tid = db_result(db_query("SELECT tid FROM {term_data} WHERE vid=%d AND name='%s'",$vid,$term));
  8. if(!$tid) {
  9. // Create a new row in term_data for this term
  10. $tid = db_next_id('{term_data}_tid');
  11. db_query("INSERT INTO {term_data} VALUES(%d, 1, '%s', '', 0)", $tid, $term);
  12. db_query("INSERT INTO {term_hierarchy} VALUES(%d, %d)", $tid, $parent);
  13. }
  14. // The next term will be a child of this one
  15. $parent = $tid;
  16.  
  17. // Now simply associate $tid with the product
  18. db_query('INSERT INTO {term_node} VALUES(%d, %d)', $product->nid, $tid);
  19. }

URL: http://level09.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.