Yoast\WP\Lib

ORM::where_any_is()publicYoast 1.0

Allows adding a WHERE clause that matches any of the conditions specified in the array. Each element in the associative array will be a different condition, where the key will be the column name.

By default, an equal operator will be used against all columns, but it can be overriden for any or every column using the second parameter.

Each condition will be ORed together when added to the final query.

Метод класса: ORM{}

Хуков нет.

Возвращает

ORM.

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

$ORM = new ORM();
$ORM->where_any_is( $values, $operator );
$values(массив) (обязательный)
The values.
$operator(строка)
The operator.
По умолчанию: '='

Код ORM::where_any_is() Yoast 22.4

public function where_any_is( $values, $operator = '=' ) {
	$data  = [];
	$query = [ '((' ];
	$first = true;
	foreach ( $values as $value ) {
		if ( $first ) {
			$first = false;
		}
		else {
			$query[] = ') OR (';
		}
		$firstsub = true;
		foreach ( $value as $key => $item ) {
			$op = \is_string( $operator ) ? $operator : ( $operator[ $key ] ?? '=' );
			if ( $op === '=' && $item === null ) {
				$op = 'IS';
			}
			if ( $firstsub ) {
				$firstsub = false;
			}
			else {
				$query[] = 'AND';
			}
			$query[] = $this->quote_identifier( $key );
			$data[]  = $item;
			$query[] = $op;
			$query[] = ( ( $item === null ) ? 'NULL' : '%s' );
		}
	}
	$query[] = '))';

	return $this->where_raw( \implode( ' ', $query ), $data );
}