WP_Network_Query::parse_orderby

Advertisement

Summery Summery

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

Syntax Syntax

WP_Network_Query::parse_orderby( string $orderby )

Parameters Parameters

$orderby

(Required) Alias for the field to order by.

Return Return

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

Source Source

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

		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;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
4.6.0 Introduced.

Advertisement

Leave a Reply