Inventory_Presser_Plugin::modify_query_for_max_price( object $query )

modify_query_for_max_price


Description Description

Modifies the $query to filter vehicles by prices for the Maximum Price Filter widget.


Top ↑

Parameters Parameters

$query

(object) (Required) An instance of the WP_Query class


Top ↑

Return Return

(void)


Top ↑

Source Source

File: inventory-presser.php

	function modify_query_for_max_price( $query )
	{
		//Do not mess with the query if it's not the main one and our CPT
		if ( ! $query->is_main_query()
			|| empty( $query->query_vars['post_type'] )
			|| $query->query_vars['post_type'] != INVP::POST_TYPE )
		{
			return;
		}

		//Get original meta query
		$meta_query = $query->get('meta_query');
		if( ! is_array( $meta_query ) )
		{
			$meta_query = array();
		}

		if ( isset( $_GET['max_price'] ) )
		{
			$meta_query['relation'] = 'AND';
			$meta_query = $this->maybe_add_meta_query(
				$meta_query,
				apply_filters( 'invp_prefix_meta_key', 'price' ),
				(int) $_GET['max_price'],
				'<=',
				'numeric'
			);
			$query->set( 'meta_query', $meta_query );
		}
	}