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

Sorts a list of objects, based on one or more orderby arguments.


Description Description


Parameters 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 Return

(array) The sorted array.


Top ↑

Source 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

Changelog
Version Description
4.7.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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