Order by menu structure

You may be able to use a WP_Query on nav_menu_item since it is its own post type. I’ve never done this but maybe it would work like you need it to, worth a shot. There are three other possibilities:

Option 1 – Get Your Nav Menu Items

There’s a functions called wp_get_nav_menu_items() which will return you an array of your menu items that you can then loop through and display. Here’s an example of how you could use it. There are a few “Gotcha!” here:

  • $item->ID is the current navigational items ID not the post_id. The post ID is now $item->object_id.
  • $item->title is the current navigational items title and not necessarily the post_title though by default it is, it can still be modified and changed. The most reliable way to get the post title is to use the object_id and pass it into get_the_title() function.

$nav_items = wp_get_nav_menu_items( 'Main Menu', array(
    'order'                  => 'ASC',                  // List ASCending or DESCending
    'orderby'                => 'title',                // Order by your usual, menu_order, post_title, etc. Check WP_Query
    'post_type'              => 'nav_menu_item',        // To be honest, I'm not sure why this is an option, leave it be.
    'post_status'            => 'publish',              // If there are private / draft posts in our menu, don't show them
    'output'                 => ARRAY_A,                // Return an Array of Objects
    'output_key'             => 'menu_order',           // Not sure what this does
    'nopaging'               => true,                   // Not sure what this does
    'update_post_term_cache' => false                   // Not sure what this does
) );

if( ! empty( $nav_items ) ) {
    foreach( $nav_items as $item ) {
        echo "{$item->title} - " . get_the_title( $item->object_id );
        echo "<br />\n";
    }
}

Option 2 – Custom Nav Walker

You could just display your menu as is using wp_nav_menu() and pass in a Custom Walker Function to modify it’s output. An example of this could be automatically pulling that menu items child pages, without actually adding those pages to the physical menu. Child Walker Class

Option 3 – Page Menu Order

Usually when I create a website for a client I have a WordPress menu and I also mirror the admin panels page order with Page Attribute menu_order. This way you could query pages using WP_Query and orderby => 'menu_order'

Image Found on codeholic.in


Other than that, in short there is no easy orderby => 'My Menu', you’ll have to find an alternative or a workaround.