5

Quick question. How to get mlid value from path of menu item. There is a function called menu_link_load() but it requires an mlid value, but I need something exacly the same function using path.

2 Answers 2

7

There's no build-in function for this. You can use menu_tree_all_data(), but it returns all the menu. After that you can compare in loops your path with the paths returend. But there is a better and easier answer. Here it is:

$mlid = array(); $q = 'your-path'; $menu_info = db_select('menu_links' , 'ml') ->condition('ml.link_path' , $q) ->fields('ml', array('mlid', 'plid')) ->execute() ->fetchAll(); foreach($menu_info as $key => $value) { $mlid[] = $menu_info[$key]->mlid; } 
2
  • Yes. Using a db query is the correct solution. One thing to note is that there can be more than one menu link for a given path. Commented Jun 11, 2014 at 8:30
  • you're right about this number of results Commented Jun 11, 2014 at 8:40
-2

Try using menu_get_item(), this should load your menu item directly from your path.

1
  • No, I've already tried it. It returns info about the page that the menu item corresponds to. But I've already found the answer. Commented Jun 11, 2014 at 8:09

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.