Why is my menu order not working with wp_nav_menu?

AFAIK there’s a non-documented orderby parameter, that can be set to menu_order.

Edit: Straight from core, inside /wp-includes/nav-menu-template.php Line# 195 (WP 3.3.1):

$sorted_menu_items = array();
foreach ( (array) $menu_items as $key => $menu_item )
    $sorted_menu_items[$menu_item->menu_order] = $menu_item;

It’s the lines immediately before the Walker runs. So the set menu_order should affect the order. You’ll just have to set it inside your page from the meta box.

In short: You shouldn’t need a custom Walker at all.

Sidnotes:

  • You don’t have to use that $indent. It make really no sense as it’s only for the source code.
  • You don’t have to make it that hard to save your meta data into single vars. Also would this add lots of queries if they’re currently not cached. Do it the following way:

    extract( get_post_custom( $item->object_id ), EXTR_SKIP );
    

Edit: extract simply makes single variables out of your custom meta data. The key is then the new name of your variable. EXTR_SKIP cares about making the variables unique as it skips double keys.

// Example: Structure of your post custom/meta data
Array( 
    [0] => array( 'example_key_name' => array( 'example_value' ) )
    [1] => array( 'another_key_name' => 'another_value' )
)
// Becomes:
$example_key_name = array( 0 => 'example_value' );
// Value can now be called as:
$example_key_name[0];
// Becomes:
$another_key_name="another_value";
// Value can be called as:
$another_key_name

The last example is not really possible, as you normally got serialized arrays as custom values (even for single values). So you’ll always have to append [0] to your variable. But this technique def. shortens code. Especially if you got really large sets of meta data per post/CPT.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)