wp_list_sort() WordPress Function

The wp_list_sort() function sorts a list of objects, based on a specified field. The function takes two arguments: the list to be sorted, and the name of the field to sort on. The function sorts the list in ascending order, based on the value of the specified field. If the field to sort on is not specified, the function will sort the list in ascending order, based on the value of the "id" field.

wp_list_sort( array $list, string|array $orderby = array(), string $order = 'ASC', bool $preserve_keys = false ) #

Sorts an array of objects or arrays based on one or more orderby arguments.


Parameters

$list

(array)(Required)An array of objects to sort.

$orderby

(string|array)(Optional) Either the field name to order by or an array of multiple orderby fields as $orderby => $order.

Default value: array()

$order

(string)(Optional) Either 'ASC' or 'DESC'. Only used if $orderby is a string.

Default value: 'ASC'

$preserve_keys

(bool)(Optional) Whether to preserve keys.

Default value: false


Top ↑

Return

(array) The sorted array.


Top ↑

Source

File: wp-includes/functions.php

function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
	if ( ! is_array( $list ) ) {
		return array();
	}

	$util = new WP_List_Util( $list );

	return $util->sort( $orderby, $order, $preserve_keys );
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.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.

Show More
Show More