WP_List_Util::sort()
Sorts the input array based on one or more orderby arguments.
Метод класса: WP_List_Util{}
Хуков нет.
Возвращает
Массив
. The sorted array.
Использование
$WP_List_Util = new WP_List_Util(); $WP_List_Util->sort( $orderby, $order, $preserve_keys );
- $orderby(строка|массив)
- Either the field name to order by or an array of multiple orderby fields as $orderby => $order.
По умолчанию: array() - $order(строка)
- Either 'ASC' or 'DESC'. Only used if $orderby is a string.
По умолчанию: 'ASC' - $preserve_keys(true|false)
- Whether to preserve keys.
По умолчанию: false
Список изменений
С версии 4.7.0 | Введена. |
Код WP_List_Util::sort() WP List Util::sort WP 6.1.1
public function sort( $orderby = array(), $order = 'ASC', $preserve_keys = false ) { if ( empty( $orderby ) ) { return $this->output; } if ( is_string( $orderby ) ) { $orderby = array( $orderby => $order ); } foreach ( $orderby as $field => $direction ) { $orderby[ $field ] = 'DESC' === strtoupper( $direction ) ? 'DESC' : 'ASC'; } $this->orderby = $orderby; if ( $preserve_keys ) { uasort( $this->output, array( $this, 'sort_callback' ) ); } else { usort( $this->output, array( $this, 'sort_callback' ) ); } $this->orderby = array(); return $this->output; }