wp_list_sort

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

Description

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

Returns (array)

The sorted array.

Parameters (4)

0. $list (array)
An array of objects to filter.
1. $orderby — Optional. (array) => array()
Either the field name to order by or an array of multiple orderby fields as $orderby => $order.
2. $order — Optional. (string) => 'ASC'
Either ASC or DESC.. Only used if $orderby is a string.
3. $preserve_keys — Optional. (bool) => false
Whether to preserve keys. Default false.

Usage

  1. if ( !function_exists( 'wp_list_sort' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // An array of objects to filter. 
  5. $list = array(); 
  6.  
  7. // Optional. Either the field name to order by or an array 
  8. // of multiple orderby fields as $orderby => $order. 
  9. $orderby = array(); 
  10.  
  11. // Optional. Either 'ASC' or 'DESC'. Only used if $orderby 
  12. // is a string. 
  13. $order = 'ASC'; 
  14.  
  15. // Optional. Whether to preserve keys. Default false. 
  16. $preserve_keys = false; 
  17.  
  18. // NOTICE! Understand what this does before running. 
  19. $result = wp_list_sort($list, $orderby, $order, $preserve_keys); 
  20.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) { 
  2. if ( ! is_array( $list ) ) { 
  3. return array(); 
  4.  
  5. $util = new WP_List_Util( $list ); 
  6. return $util->sort( $orderby, $order, $preserve_keys );