[wp-trac] [WordPress Trac] #28126: wp_nav_menu defaults to 'first' non-empty menu, without specifying an order.

WordPress Trac noreply at wordpress.org
Mon May 5 04:17:46 UTC 2014


#28126: wp_nav_menu defaults to 'first' non-empty menu, without specifying an
order.
--------------------------+-----------------------------
 Reporter:  thingalon     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Menus         |    Version:  3.9
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 According to the {{{wp_nav_menu}}} documentation, it should display the
 first non-empty menu if called with no parameters. (Documentation link:
 http://codex.wordpress.org/Function_Reference/wp_nav_menu)

 However, 'first' is neither defined in the documentation, nor in code. It
 displays the first non-empty menu found by an unsorted query.

 For example, if I call {{{wp_nav_menu();}}}, the following query is used:
 {{{
 SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON
 t.term_id = tt.term_id WHERE tt.taxonomy IN ('nav_menu')
 }}}

 I suggest the following change, which selects the first non-empty menu by
 name:
 {{{
 #!diff
 --- wp-includes/nav-menu-template.php
 +++ wp-includes/nav-menu-template.php
 @@ -280,5 +280,5 @@
         // get the first menu that has items if we still can't find a menu
         if ( ! $menu && !$args->theme_location ) {
 -               $menus = wp_get_nav_menus();
 +               $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
                 foreach ( $menus as $menu_maybe ) {
                         if ( $menu_items = wp_get_nav_menu_items(
 $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) {
 }}}

 That will at least produce reliably consistent results, and remains
 consistent with the order that nav menus are displayed in wp-admin.

 Alternately, the problem may be the documentation; it may need to be made
 clearer that the 'first' item is arbitrarily selected.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28126>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list