How to enable menu link when creating a new node? I try to enable the menu link programmatically, here is how I do it:

function create_menu_link() {
    $node = new stdClass();
    $node-&gt;type = 'mytype';
    node_object_prepare($node);

    $node-&gt;menu['link-title'] = $menu_title;

    node_save($node);
}


But setting only the title is not working. In $node-&gt;menu there is some other variables like mlid and plid which are set to 0 it has to do with this ? The menu_name is set to main-menu:0, module is set to menu.
You'll need to create the menu item separately, using menu_link_save

$item = array(
  'menu_name' =&gt; 'main-menu',
  'link_title' =&gt; $node-&gt;title,
  'link_path' =&gt; 'node/'. $node-&gt;nid,
);
menu_link_save($item);