Used By
Used By | Description |
---|---|
wp-includes/class-wp-site-query.php: WP_Site_Query::get_site_ids() | Used internally to get a list of site IDs matching the query vars. |
Parses and sanitizes ‘orderby’ keys passed to the site query.
(string) (Required) Alias for the field to order by.
(string|false) Value to used in the ORDER clause. False otherwise.
File: wp-includes/class-wp-site-query.php
protected function parse_orderby( $orderby ) { global $wpdb; $parsed = false; switch ( $orderby ) { case 'site__in': $site__in = implode( ',', array_map( 'absint', $this->query_vars['site__in'] ) ); $parsed = "FIELD( {$wpdb->blogs}.blog_id, $site__in )"; break; case 'network__in': $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); $parsed = "FIELD( {$wpdb->blogs}.site_id, $network__in )"; break; case 'domain': case 'last_updated': case 'path': case 'registered': $parsed = $orderby; break; case 'network_id': $parsed = 'site_id'; break; case 'domain_length': $parsed = 'CHAR_LENGTH(domain)'; break; case 'path_length': $parsed = 'CHAR_LENGTH(path)'; break; case 'id': $parsed = "{$wpdb->blogs}.blog_id"; break; } if ( ! empty( $parsed ) || empty( $this->meta_query_clauses ) ) { return $parsed; } $meta_clauses = $this->meta_query->get_clauses(); if ( empty( $meta_clauses ) ) { return $parsed; } $primary_meta_query = reset( $meta_clauses ); if ( ! empty( $primary_meta_query['key'] ) && $primary_meta_query['key'] === $orderby ) { $orderby = 'meta_value'; } switch ( $orderby ) { case 'meta_value': if ( ! empty( $primary_meta_query['type'] ) ) { $parsed = "CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})"; } else { $parsed = "{$primary_meta_query['alias']}.meta_value"; } break; case 'meta_value_num': $parsed = "{$primary_meta_query['alias']}.meta_value+0"; break; default: if ( isset( $meta_clauses[ $orderby ] ) ) { $meta_clause = $meta_clauses[ $orderby ]; $parsed = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})"; } } return $parsed; }
Version | Description |
---|---|
4.6.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_site_query/parse_orderby