Assign menu programmatically upon saving node I'm using Superfish module for my menu. I have product parent menu where I need to display the 3 categories as sub-menu. Those 3 categories has been added to the menu with the help of Taxonomy menu module.

I would like to assign a menu automatically based from the nodes category.

For example:-

"Node 1" has "Category 1" term, then the node menu will be assigned to "Category 1". Something like below:-

-Product
 --Category 1
    ---Node 1
    ---Node 2
  --Category 2
    ---Node 3
    ---Node 4
Please try this

/**
 * Implements hook_node_insert().
 */
function YOUR_MODUEL_node_insert($node){
  create_node_menu($node, 'insert');
}

/**
 * Implements hook_node_update().
 */
function YOUR_MODUEL_node_update($node){
  create_node_menu($node, 'update');
}

function create_node_menu($node, $action_type){
  if($node-&gt;type == 'YOUR_NODE_TYPE'){
    $category = $node-&gt;field_category[LANGUAGE_NONE][0]['value'];
    $menu_name = '';
    switch($category){
      case "A":
        $menu_name = 'menu-menu-a';
        break;
      case "B":
        $menu_name = 'menu-menu-b';
        break;
      case "C":
        $menu_name = 'menu-menu-c';
        break;
    }
    if(!empty($menu_name)){
      $item = array(
        'menu_name' =&gt; $menu_name,
        'link_title' =&gt; $node-&gt;title,
        'link_path' =&gt; 'node/'. $node-&gt;nid,
      );
// update already created menu link
      if($action_type == 'update'){
        $mlid = db_select('menu_links' , 'ml')
            -&gt;condition('ml.link_path', 'node/'.$node-&gt;nid)
            -&gt;condition('ml.menu_name', $menu_name)
            -&gt;fields('ml' , array('mlid'))
            -&gt;execute()
            -&gt;fetchField();
        $item['mlid'] = $mlid;
      }
      $mlid = menu_link_save($item);
      menu_cache_clear_all();
    }
  }
}


Hope this will help.