You are here

25 August 2014

There are many functions for menus, but since Drupal is not hierarchical but is modular, that's why menu doesn't have node requirement and the opposite way around. So this snippet shows how to get node menu item (mlid) by node id (nid) in Drupal 7. The fastest way to do it is to run a simple query.

Source code viewer
  1. $mlid = db_select('menu_links' , 'ml')
  2. ->condition('ml.link_path', 'node/'.$nid)
  3. ->condition('ml.menu_name', $menu_name)
  4. ->fields('ml' , array())
  5. ->range(0, 1)
  6. ->execute()
  7. ->fetchAll();
  8.  
  9. dpm($mlid);
Programming Language: PHP