wp_list_sort

The timeline below displays how wordpress function wp_list_sort has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Sorts an array of objects or arrays based on one or more orderby arguments.
 *
 * @since 4.7.0
 *
 * @param array        $input_list    An array of objects or arrays to sort.
 * @param string|array $orderby       Optional. Either the field name to order by or an array
 *                                    of multiple orderby fields as `$orderby => $order`.
 *                                    Default empty array.
 * @param string       $order         Optional. Either 'ASC' or 'DESC'. Only used if `$orderby`
 *                                    is a string. Default 'ASC'.
 * @param bool         $preserve_keys Optional. Whether to preserve keys. Default false.
 * @return array The sorted array.
 */
function wp_list_sort($input_list, $orderby = array(), $order = 'ASC', $preserve_keys = false)
{
    if (!is_array($input_list)) {
        return array();
    }
    $util = new WP_List_Util($input_list);
    return $util->sort($orderby, $order, $preserve_keys);
}

WordPress Version: 6.1

/**
 * Sorts an array of objects or arrays based on one or more orderby arguments.
 *
 * @since 4.7.0
 *
 * @param array        $list          An array of objects or arrays to sort.
 * @param string|array $orderby       Optional. Either the field name to order by or an array
 *                                    of multiple orderby fields as $orderby => $order.
 * @param string       $order         Optional. Either 'ASC' or 'DESC'. Only used if $orderby
 *                                    is a string.
 * @param bool         $preserve_keys Optional. Whether to preserve keys. Default false.
 * @return array The sorted array.
 */
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);
}

WordPress Version: 5.9

/**
 * Sorts an array of objects or arrays based on one or more orderby arguments.
 *
 * @since 4.7.0
 *
 * @param array        $list          An array of objects to sort.
 * @param string|array $orderby       Optional. Either the field name to order by or an array
 *                                    of multiple orderby fields as $orderby => $order.
 * @param string       $order         Optional. Either 'ASC' or 'DESC'. Only used if $orderby
 *                                    is a string.
 * @param bool         $preserve_keys Optional. Whether to preserve keys. Default false.
 * @return array The sorted array.
 */
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);
}

WordPress Version: 5.1

/**
 * Sorts a list of objects, based on one or more orderby arguments.
 *
 * @since 4.7.0
 *
 * @param array        $list          An array of objects to sort.
 * @param string|array $orderby       Optional. Either the field name to order by or an array
 *                                    of multiple orderby fields as $orderby => $order.
 * @param string       $order         Optional. Either 'ASC' or 'DESC'. Only used if $orderby
 *                                    is a string.
 * @param bool         $preserve_keys Optional. Whether to preserve keys. Default false.
 * @return array The sorted array.
 */
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);
}

WordPress Version: 4.7

/**
 * Sorts a list of objects, based on one or more orderby arguments.
 *
 * @since 4.7.0
 *
 * @param array        $list          An array of objects to filter.
 * @param string|array $orderby       Optional. Either the field name to order by or an array
 *                                    of multiple orderby fields as $orderby => $order.
 * @param string       $order         Optional. Either 'ASC' or 'DESC'. Only used if $orderby
 *                                    is a string.
 * @param bool         $preserve_keys Optional. Whether to preserve keys. Default false.
 * @return array The sorted array.
 */
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);
}