WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WP_Meta_Query::sanitize_query() public WP 4.1.0

Ensure the 'meta_query' argument passed to the class constructor is well-formed.

Eliminates empty items and ensures that a 'relation' is set.

{} Это метод класса: WP_Meta_Query{}

Хуков нет.

Возвращает

Массив. Sanitized array of query clauses.

Использование

$WP_Meta_Query = new WP_Meta_Query();
$WP_Meta_Query->sanitize_query( $queries );
$queries(массив) (обязательный)
Array of query clauses.

Список изменений

С версии 4.1.0 Введена.

Код WP_Meta_Query::sanitize_query() WP 5.5.3

<?php
public function sanitize_query( $queries ) {
	$clean_queries = array();

	if ( ! is_array( $queries ) ) {
		return $clean_queries;
	}

	foreach ( $queries as $key => $query ) {
		if ( 'relation' === $key ) {
			$relation = $query;

		} elseif ( ! is_array( $query ) ) {
			continue;

			// First-order clause.
		} elseif ( $this->is_first_order_clause( $query ) ) {
			if ( isset( $query['value'] ) && array() === $query['value'] ) {
				unset( $query['value'] );
			}

			$clean_queries[ $key ] = $query;

			// Otherwise, it's a nested query, so we recurse.
		} else {
			$cleaned_query = $this->sanitize_query( $query );

			if ( ! empty( $cleaned_query ) ) {
				$clean_queries[ $key ] = $cleaned_query;
			}
		}
	}

	if ( empty( $clean_queries ) ) {
		return $clean_queries;
	}

	// Sanitize the 'relation' key provided in the query.
	if ( isset( $relation ) && 'OR' === strtoupper( $relation ) ) {
		$clean_queries['relation'] = 'OR';
		$this->has_or_relation     = true;

		/*
		* If there is only a single clause, call the relation 'OR'.
		* This value will not actually be used to join clauses, but it
		* simplifies the logic around combining key-only queries.
		*/
	} elseif ( 1 === count( $clean_queries ) ) {
		$clean_queries['relation'] = 'OR';

		// Default to AND.
	} else {
		$clean_queries['relation'] = 'AND';
	}

	return $clean_queries;
}