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
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;
}
-
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. Jun 11, 2014 at 8:30
-
Try using menu_get_item(), this should load your menu item directly from your path.
-
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.– DavidJun 11, 2014 at 8:09