WP_Network_Query::parse_orderby() WordPress Method

The WP_Network_Query::parse_orderby() method is used to parse the 'orderby' parameter of the WP_Network_Query class. The 'orderby' parameter is used to specify how the networks should be ordered.

WP_Network_Query::parse_orderby( string $orderby ) #

Parses and sanitizes ‘orderby’ keys passed to the network query.


Parameters

$orderby

(string)(Required)Alias for the field to order by.


Top ↑

Return

(string|false) Value to used in the ORDER clause. False otherwise.


Top ↑

Source

File: wp-includes/class-wp-network-query.php

	protected function parse_orderby( $orderby ) {
		global $wpdb;

		$allowed_keys = array(
			'id',
			'domain',
			'path',
		);

		$parsed = false;
		if ( 'network__in' === $orderby ) {
			$network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) );
			$parsed      = "FIELD( {$wpdb->site}.id, $network__in )";
		} elseif ( 'domain_length' === $orderby || 'path_length' === $orderby ) {
			$field  = substr( $orderby, 0, -7 );
			$parsed = "CHAR_LENGTH($wpdb->site.$field)";
		} elseif ( in_array( $orderby, $allowed_keys, true ) ) {
			$parsed = "$wpdb->site.$orderby";
		}

		return $parsed;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.