title: How do I generate a custom menu/sub-menu system using wp_get_nav_menu_items in WordPress?
body: <p>I have an html structure that requires customization of the <code>wp_nav_menu</code> code.</p>
  
  <p>This is the html I need to generate:</p>
  
  <pre><code>&lt;ul class="main-nav"&gt;
      &lt;li class="item"&gt;
          &lt;a href="http://example.com/?p=123" class="title"&gt;Title&lt;/a&gt;
          &lt;a href="http://example.com/?p=123" class="desc"&gt;Description&lt;/a&gt;
          &lt;ul class="sub-menu"&gt;
              &lt;li class="item"&gt;
                  &lt;a href="http://example.com/?p=123" class="title"&gt;Title&lt;/a&gt;
                  &lt;a href="http://example.com/?p=123" class="desc"&gt;Description&lt;/a&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
       &lt;li class="item"&gt;
          &lt;a href="http://example.com/?p=123" class="title"&gt;Title&lt;/a&gt;
          &lt;a href="http://example.com/?p=123" class="desc"&gt;Description&lt;/a&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I am currently using <code>wp_get_nav_menu_items</code> to get all the items from my menu as an array.</p>
  
  <p>Right now I am able to generate the above html <strong>without the sub-menus</strong> using the following code:</p>
  
  <pre><code>&lt;?php
  
  $menu_name = 'main-nav';
  $locations = get_nav_menu_locations()
  $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
  $menuitems = wp_get_nav_menu_items( $menu-&gt;term_id, array( 'order' =&gt; 'DESC' ) );
  
  foreach ( $menuitems as $item ):
  
      $id = get_post_meta( $item-&gt;ID, '_menu_item_object_id', true );
      $page = get_page( $id );
      $link = get_page_link( $id ); ?&gt;
  
      &lt;li class="item"&gt;
          &lt;a href="&lt;?php echo $link; ?&gt;" class="title"&gt;
              &lt;?php echo $page-&gt;post_title; ?&gt;
          &lt;/a&gt;
          &lt;a href="&lt;?php echo $link; ?&gt;" class="desc"&gt;
              &lt;?php echo $page-&gt;post_excerpt; ?&gt;
          &lt;/a&gt;
      &lt;/li&gt;
  
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>I would have generated the menu using the <code>wp_nav_menu</code> function but I still need the description shown using <code>$page-&gt;post_excerpt</code>.</p>
  
  <p>I've found that there is a property for each item called <code>$item-&gt;menu_item_parent</code> which gives the ID of the parent menu item.</p>
  
  <p>How would I generate the sub-menu in my <code>foreach</code> loop?
  Or is there a really simple way using <code>wp_nav_menu</code> which Google forgot to mention?</p>