Builder::where( string $column, string|null $operator = null, string|null $value = null )

Add the available where clauses on the model.


Parameters

$column

(string) (Required) The name of the column

$operator

(string|null) (Optional) The operator to use against to compare or the value

Default value: null

$value

(string|null) (Optional) The value to compare against with.

Default value: null


Top ↑

Return

($this)


Top ↑

Source

File: src/Events/Custom_Tables/V1/Models/Builder.php

	public function where( $column, $operator = null, $value = null ) {
		$this->invalid = false;

		// If only 2 arguments are provided use the second argument as the value and assume the operator is "="
		if ( func_num_args() === 2 ) {
			$value    = $operator;
			$operator = '=';
		}

		if ( $this->invalid_operator( $operator ) ) {
			$this->invalid = true;

			return $this;
		}

		$model = $this->set_data_to_model( [ $column => $value ] );

		if ( ! $model->enable_single_validation( $column )->validate( [ $column ] ) ) {
			$this->invalid = true;

			return $this;
		}

		list( $data, $format ) = $model->format();

		if ( empty( $data ) || ! array_key_exists( $column, $data ) ) {
			$this->invalid = true;

			return $this;
		}

		if ( array_key_exists( $column, $format ) ) {
			global $wpdb;
			$format = $format[ $column ];

			$this->wheres[] = $wpdb->prepare( "(`{$column}` {$operator} {$format})", $data[ $column ] );

			return $this;
		}

		if ( $value === null ) {
			$this->wheres[] = "(`{$column}` {$operator} NULL)";
		}

		return $this;
	}

Top ↑

Changelog

Changelog
Version Description
6.0.0 Introduced.