Inventory_Presser_Additional_Listings_Pages::get_query_meta_array( array $rule )

Turns additional listing page rules into SQL query pieces.


Parameters

$rule

(array) (Required)


Return

(array)


Source

File: includes/class-additional-listings-pages.php

	public static function get_query_meta_array( $rule ) {
		// There may be no filter in the rule.
		if ( '' === $rule['key'] ) {
			return array();
		}
		$new = null;
		switch ( $rule['operator'] ) {
			case 'contains':
				$new = array(
					'relation' => 'AND',
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', $rule['key'] ),
						'compare' => 'LIKE',
						'value'   => $rule['value'],
					),
				);
				break;

			case 'does_not_exist':
				$new = array(
					'relation' => 'AND',
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', $rule['key'] ),
						'compare' => 'NOT EXISTS',
					),
				);
				break;

			case 'equal_to':
			case 'not_equal_to':
				$new = array(
					'relation' => 'AND',
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', $rule['key'] ),
						'compare' => ( 'equal_to' === $rule['operator'] ? '=' : '!=' ),
						'value'   => $rule['value'],
					),
				);
				break;

			case 'exists':
				$new = array(
					'relation' => 'AND',
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', $rule['key'] ),
						'compare' => 'EXISTS',
					),
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', $rule['key'] ),
						'value'   => array( '', 0 ),
						'compare' => 'NOT IN',
					),
				);
				break;

			case 'greater_than':
			case 'less_than':
				$new = array(
					'relation' => 'AND',
					array(
						'key'     => apply_filters( 'invp_prefix_meta_key', $rule['key'] ),
						'compare' => ( 'greater_than' === $rule['operator'] ? '>' : '<' ),
						'value'   => ( (float) $rule['value'] ),
						'type'    => 'NUMERIC',
					),
				);
				break;
		}
		return $new;
	}