WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 13 months ago

#15533 reopened defect (bug)

wp_get_nav_menu_items order doesn't work

Reported by: markoheijnen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 3.0
Component: Menus Keywords: 2nd-opinion
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 (7)

comment:1 @scribu4 years ago

  • Description modified (diff)

comment:2 @nacin4 years ago

  • Version changed from 3.1 to 3.0

comment:3 @c3mdigital19 months 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.

comment:4 @nacin19 months ago

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

comment:5 @markoheijnen19 months 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?

comment:6 @SergeyBiryukov19 months ago

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

comment:7 @DrewAPicture13 months 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.

Note: See TracTickets for help on using tickets.