[wp-trac] [WordPress Trac] #15533: wp_get_nav_menu_items order doesn't work

WordPress Trac noreply at wordpress.org
Sun Jun 25 19:12:21 UTC 2017


#15533: wp_get_nav_menu_items order doesn't work
-------------------------------------------------+-------------------------
 Reporter:  markoheijnen                         |       Owner:
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Menus                                |  Review
 Severity:  normal                               |     Version:  3.0
 Keywords:  needs-docs good-first-bug needs-     |  Resolution:
  patch                                          |     Focuses:
-------------------------------------------------+-------------------------

Comment (by DrewAPicture):

 So, some interesting history here.

 The sorting logic was originally introduced in [13344], and in that case,
 the output order was manually overwritten with the value of `$item` in the
 foreach.

 When the menus UI came in in [14248], we switched to using an incrementer
 on the `output_key` field for each post in the list. At that time, we
 started passing `order => 'ASC'` in the `get_posts()` args, and the
 `_sort_nav_menu_items()` callback was introduced along with the
 `$_menu_item_sort_prop` global – needed for use in the sort callback.

 The use of the incrementer is puzzling in that it only makes sense in the
 context that `output_key` is `menu_order`. For instance, in
 `wp_nav_menu_update_menu_items()`, the `output_key` argument is passed as
 `ID`. This makes sense in terms of wanting the unordered posts, but less
 less sense when you consider that the post IDs are then being
 ''incremented'' in the foreach.

 In [38928] when `wp_list_sort()` was introduced, we started passing a
 hard-coded `order` value of 'ASC', completely disregarding the
 `$args['order']` value. Now, obviously, this ticket was created 7 years
 ago, which makes anything past [14557] kind of irrelevant, but interesting
 nonetheless.

 All that said, I think the best thing to do here is explain in the
 parameter notation for `$args` that 'order' will be ignored when 'output'
 is `ARRAY_A`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/15533#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list