Warning: This function has been deprecated. Use wp_list_sort() instead.

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_sort_nav_menu_items() WordPress Function

The sort_nav_menu_items() function sorts the given menu items by the given criteria. The criteria can be either a string or an array. If the criteria is a string, it must be a valid SQL ORDER BY clause. If the criteria is an array, it must be an array of column names.

_sort_nav_menu_items( object $a, object $b ) #

Sort menu items by the desired key.


Parameters

$a

(object)(Required)The first object to compare

$b

(object)(Required)The second object to compare


Top ↑

Return

(int) -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.


Top ↑

Source

File: wp-includes/deprecated.php

function _sort_nav_menu_items( $a, $b ) {
	global $_menu_item_sort_prop;

	_deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort()' );

	if ( empty( $_menu_item_sort_prop ) )
		return 0;

	if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) )
		return 0;

	$_a = (int) $a->$_menu_item_sort_prop;
	$_b = (int) $b->$_menu_item_sort_prop;

	if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop )
		return 0;
	elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop )
		return $_a < $_b ? -1 : 1;
	else
		return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Use wp_list_sort()
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.