wp_get_nav_menu_items order doesn’t work

I am using this function

$args = array (
   'order' => 'DESC',
);

$items = wp_get_nav_menu_items( $custom_menu, $args );

then, if I change args to

Read More
$args = array (
   'order' => 'ASC',
);

and the result is still the same.

Anybody have suggestion?

Related posts

1 comment

  1. When you look in WordPress source code, you will find reason for that. On line 538 of nav-menu.php you’ll find:

    if ( ARRAY_A == $args['output'] ) {
        $GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
            usort($items, '_sort_nav_menu_items');
            $i = 1;
            foreach( $items as $k => $item ) {
                $items[$k]->$args['output_key'] = $i++;
            }
    }
    

    I didn’t check why, but it looks like this sorting doesn’t work right. The easiest thing you can do to fixthis is to change output type to disable this sorting.

    So when you add 'output'=>OBJECT or 'output'=>ARRAY_N to your args it should work just fine.

    PS. It’s even known bug: http://core.trac.wordpress.org/ticket/15533

Comments are closed.