tribe_normalize_orderby( string|array $orderby, string $order = 'ASC' )
Normalizes an orderby
string or array to an map of keys and orders.
Contents
Note the function and the variables use the "orderby" (no spaces) name to stick with the WordPress query standard.
Parameters
- $orderby
-
(string|<span class="array">array) (Required) Either an
orderby
key, a list oforderby
keys or a map oforderby
clauses. - $order
-
(string) (Optional) The default order that should be applied to
orderby
entries that lack one.Default value: 'ASC'
Return
(array) The normalized orderby
array, in the format supported by WordPress queries: [ <key_1> => <order>, <key_2> => <order>, ... ]
.
Source
File: src/functions/query.php
function tribe_normalize_orderby( $orderby, $order = 'ASC' ) { // Make the `orderby` part an array. $orderby_arr = (array) $orderby; $normalized = []; foreach ( $orderby_arr as $by_key => $direction ) { if ( empty( $direction ) ) { continue; } if ( is_numeric( $by_key ) ) { // It's an entry where the key is just listed, relying on the default order. $by_key = $direction; $direction = $order; } $normalized[ $by_key ] = $direction; } return $normalized; }
Changelog
Version | Description |
---|---|
4.12.6 | Introduced. |