Trying to copy data from field A (plain text field) to field B (entity reference field with taxonomy) within the same content type. The taxonomy terms used in field B are the same terms used in old field (field A).
Below is my first attempt in writing a hook for field copy (using hook_update_N) but its not working.
function mymodule_update_8001() {
$node_type = "test_content_type";
$nidArray = db_query("SELECT nid FROM node WHERE type = '%s' ", $node_type);
foreach ($nidArray as $nid) {
$node = node_load($nid);
$termString = $node->field_a;
$termObject = taxonomy_term_load_multiple_by_name($termString);
$node->field_b->target_id = $termObject->tid;
$node->revision = TRUE;
node_save($node);
}
}
Any help on this would be greatly appreciated.