menu_item_parent == 0) { $menu_structure[$menu_item->ID] = array( 'title' => $menu_item->title, 'url' => $menu_item->url, 'children' => array() ); } else { // If the menu item has a parent, add it as a child of its parent $parent_id = $menu_item->menu_item_parent; $menu_structure[$parent_id]['children'][] = array( 'title' => $menu_item->title, 'url' => $menu_item->url ); } } // Loop through menu items with no parents (parents are the "parent" items) foreach ($menu_structure as $menu_item_id => $menu_item_data) { $menuItemTitle = $menu_item_data['title']; $menuItemSlug = $menu_item_data['url']; ?>