Title: _sort_nav_menu_items
Published: April 25, 2014
Last modified: April 28, 2025

---

# _sort_nav_menu_items( object $a, object $b ): int

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#wp--skip-link--target)

This function has been deprecated since 4.7.0. Use wp_list_sort() instead.

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

Sort menu items by the desired key.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#parameters)󠁿

 `$a`objectrequired

The first object to compare

`$b`objectrequired

The second object to compare

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#source)󠁿

    ```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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/deprecated.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/deprecated.php#L3907)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/deprecated.php#L3907-L3927)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#related)󠁿

| Uses | Description | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_sort_nav_menu_items/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Deprecated. Use [wp_list_sort()](https://developer.wordpress.org/reference/functions/wp_list_sort/)  | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_sort_nav_menu_items%2F)
before being able to contribute a note or feedback.