Trying to store submenu items to render out after main menu

Yesterday I had the same kind of problem and I decided to ditch the walker alltogether and use the wp_get_nav_menu_object and wp_get_nav_menu_items functions instead.

If you var_dump($menu_items) you can see which properties are available.

Here’s a snippet of my code that builds the menu named ‘main’ for my twitter bootstrap menu:

    $menu_name="main"; // name of your menu
    $menu = wp_get_nav_menu_object($menu_name);

    $menu_items = wp_get_nav_menu_items($menu->term_id);



    $tmpWPMenu = ""; // string variable where the menu is stored

    // collect the menu-items (if any) and store them temporarily in 
    // the $tmpChildren array with the $key = id of parent

    $tmpChildren = array();
    foreach ( (array) $menu_items as $key => $menu_item ) {
        if (intval($menu_item->menu_item_parent) > 0) {
            $tmpChildren[$menu_item->menu_item_parent][] = $menu_item;
        }
    }

   // Now loop again and build it, 
   // when a matching ID is encountered in the $tmpChildren array, build the submenu:
    foreach ( (array) $menu_items as $key => $menu_item ) {
        $title = $menu_item->title;
        $url = $menu_item->url;

        if (intval($menu_item->menu_item_parent) == 0) {


            // Does $tmpChildren contain a $key that is the id of this menu-item?
            if (array_key_exists($menu_item->ID, $tmpChildren)) {

                $tmpWPMenu .= '<li class="dropdown">';
                $tmpWPMenu .= ' <a href="#" class="dropdown-toggle" data-toggle="dropdown"></i> '.$title.' <b class="caret"></b></a>';


                $tmpWPMenu .= ' <ul class="dropdown-menu">';
                foreach ($tmpChildren[$menu_item->ID] as $subMenuItem) {
                    $tmpWPMenu .= '<li><a href="http://wordpress.stackexchange.com/ik/"><!--<i class="glyphicon glyphicon-user"></i>--> ' . $subMenuItem->title . '</a></li>';
                }
                $tmpWPMenu .= ' </ul>';
                $tmpWPMenu .= '</li>';

            } else {

                $tmpWPMenu .= '<li>';
                $tmpWPMenu .= '<a href="#"></i> '.$title.' </a>';
                $tmpWPMenu .= '</li>';

            }

        }



    }

    // Do something with the $tmpWPMenu, in my case I pass it 
    // to the Smarty template engine that I use
    $tmpNavBarFindAndReplace['wp_menu'] = $tmpWPMenu;


    print $gBSOManager->pPageO->mRender($tmpNavBarFindAndReplace, 'mijn/navbar.html',true);

I hope this might help (or provide insight) 🙂
Cheers,
T