This question already has an answer here:

When I programmatically create a taxonomy term and update node, in hook_node_presave() I have the following code:

$node->field_status_tags[LANGUAGE_NONE][]['tid'] = $value->tid;

I get the following error:

Notice: Array to string conversion in DrupalDefaultEntityController->cacheGet() (line 369 of includes\entity.inc).

This is the code I am using. I'm sure the value for tid is right.

 * Implements hook_node_presave().
function love_layout_node_presave($node) {
   *if ($node->nid && $node->moderate) {
   *  // Reset votes when node is updated:
   *  $node->score = 0;
   *  $node->users = '';
   *  $node->votes = 0;
  if($node->type == 'status') {

   $pattern = '/#([^\\#|.]+)#/';
   preg_match_all($pattern, $node->title, $matches, PREG_SET_ORDER);
   $node->field_status_tags[LANGUAGE_NONE] = array();

      $term_name = $value[1];
      $term = taxonomy_get_term_by_name($term_name);
       $term = new stdClass();
       $term->vid = 1;
       $term->name = $term_name;
       $term = taxonomy_get_term_by_name($term_name);
       foreach ($term as $value) {
          $node->field_status_tags[LANGUAGE_NONE][]['tid'] = (int) $value->tid;
        foreach ($term as $key => $value) {

marked as duplicate by kiamlaluno Sep 12 '13 at 22:52



Basically I would think that $value->tid when you are using it is not a number but an array. Because I do the same assignment and it works.

So I suspect you are misusing the taxonomy term you created. This is how I created the taxonomy in a function:

function create_new_term($term_name, $vocabulary_id, $language = LANGUAGE_NONE, $i18n_tsid = 0){
  $tid = db_insert('taxonomy_term_data')
  print "Created new taxonomy term tid #".$tid." $term_name in $vocabulary_id<br>"."\n";
  return $tid;

And here is how I add that term:

$my_new_node->field_my_term['LANGUAGE_NONE'] [] ['tid'] = $returned_tid;

I hope this helps.


This appears to be the same as one the existing core issues (https://drupal.org/node/1525176).

As of 2013-09-11, there are patches in the issue, but it still remains open.
