Make WordPress Core

Opened 7 years ago

Last modified 2 months ago

#15533 assigned defect (bug)

wp_get_nav_menu_items order doesn't work

Reported by: markoheijnen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: needs-docs good-first-bug needs-patch
Focuses: Cc:

Description (last modified by scribu)

Argument order doesn't work when output is ARRAY_A since on the end of function wp_get_nav_menu_items there is a usort on the $items array what will be returned.

Since out ARRAY_A is the default output this can give strange behaviour.

The code that gives the problem:

	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++;

Change History (12)

#1 @scribu
7 years ago

  • Description modified (diff)

#2 @nacin
6 years ago

  • Version changed from 3.1 to 3.0

#3 @c3mdigital
4 years ago

  • Keywords close 2nd-opinion needs-codex added
  • Resolution set to invalid
  • Status changed from new to closed

The 'orderby' argument is ignored when output is set to ARRAY_A but you can specify orderby in the 'output_key' argument then order works as expected. Is there a reason this function uses the output_key argument instead of orderby?

I think we just need to update the codex.

#4 @nacin
4 years ago

Seems like there is something legitimate here, though unsure what. Please re-open or open a new ticket for reconsideration.

#5 @markoheijnen
4 years ago

I'm not sure it this should be closed. Can't we just use the value of orderby as the value for output_key when output_key isn't provided?

#6 @SergeyBiryukov
4 years ago

  • Keywords close removed
  • Resolution invalid deleted
  • Status changed from closed to reopened

#7 @DrewAPicture
3 years ago

  • Keywords needs-codex removed

Feel free to re-tag for docs changes if there ends up being no no consensus for leaving this ticket open.

#8 @chriscct7
21 months ago

  • Keywords needs-docs added; 2nd-opinion removed
  • Owner set to DrewAPicture
  • Severity changed from minor to normal
  • Status changed from reopened to assigned

Reassigning to drew per last comment

#9 @DrewAPicture
21 months ago

  • Status changed from assigned to accepted

#10 @DrewAPicture
10 months ago

  • Keywords good-first-bug added
  • Owner DrewAPicture deleted
  • Status changed from accepted to assigned

@c3mdigital I'll bet the reason output_key exists is to explicitly make it possible to differentiate the order of posts queried via get_posts() vs displayed via wp_get_nav_menu_items().

I think all we really need here is some clarifying documentation for the purpose/intent output_key argument.

This ticket was mentioned in Slack in #docs by morganestes. View the logs.

9 months ago

#12 @welcher
2 months ago

  • Keywords needs-patch added
Note: See TracTickets for help on using tickets.