WP_Customize_Nav_Menu_Item_Setting::sort_wp_get_nav_menu_items( WP_Post[] $items, WP_Term $menu, array $args )

Re-apply the tail logic also applied on $items by wp_get_nav_menu_items().

Description Description

See also See also

Top ↑

Parameters Parameters


(WP_Post[]) (Required) An array of menu item post objects.


(WP_Term) (Required) The menu object.


(array) (Required) An array of arguments used to retrieve menu item objects.

Top ↑

Return Return

(WP_Post[]) Array of menu item objects.

Top ↑

Source Source

File: wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

	public static function sort_wp_get_nav_menu_items( $items, $menu, $args ) {
		// @todo We should probably re-apply some constraints imposed by $args.
		unset( $args['include'] );

		// Remove invalid items only in front end.
		if ( ! is_admin() ) {
			$items = array_filter( $items, '_is_valid_nav_menu_item' );

		if ( ARRAY_A === $args['output'] ) {
			$items = wp_list_sort(
					$args['output_key'] => 'ASC',
			$i     = 1;

			foreach ( $items as $k => $item ) {
				$items[ $k ]->{$args['output_key']} = $i++;

		return $items;

Top ↑

Changelog Changelog

Version Description
4.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.