WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a custom menu handler for the back end, sorting the via a drag drop based on CMS Page Order.

The problem now is that it seems that it's not possible to sort wp_nav_menu in any other way than the default one, can that be really be true?

share|improve this question
Show us what you have tried already to make answers possible. – toscho Jul 18 '12 at 23:42
@toscho I am yet to find something to try out, the only code I've found is the one that reverses the array, not quite what I'm looking for. Maybe it's possible to do something in the walker, but it's too complex for me to understand (it's from the roots framework: pastebin.com/W5ja5dGJ) – INT Jul 18 '12 at 23:56
@toscho I also found this, but not really sure if it applies to my problem: wordpress.stackexchange.com/a/52408/2830 Tried this to no avail: pastebin.com/5NHqC2S1 – INT Jul 19 '12 at 18:50
up vote 5 down vote accepted

The nav_menu_items are already sorted by menu_order.

When you go into the Appearance -> Menus and arrange the order menu the menu_order of each menu item gets updated.

To change the orderby parameter in the query that displays the menu you can use pre_get_posts to alter it. Example:

add_action( 'pre_get_posts', 'wpse_sort_nav' );
function wpse_sort_nav( $query ) {
        if ( $query->is_main_query() && get_query_var( 'post_type' ) == 'nav_menu_item' )
            $query->set( 'orderby', 'ID' );

ID and menu_order are your only real options for sorting using the default post table. There is no title and the post_name is the same as the ID.

You could add additional parameters to the pre_get_posts filter using the meta data stored with each nav_menu_item.

Nav Menu metadata:

_menu_item_classes _menu_item_xfn

share|improve this answer
Thanks for your comprehensive answer. I realize now, that the approach I had to this issue the opposite of what I should be looking for. I have implented a custom menu, similar to the one that you find in Apperance -> Menus. What I want to do is send the order created in this menu to wp_nav_menu so that is the order seen in the front end. Sorry for this. I put up a new question if you have any insight (wordpress.stackexchange.com/q/59279/2830) Thanks! – INT Jul 22 '12 at 15:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.