Inventory_Presser_Plugin::modify_query_for_max_price( object $query )

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


Parameters

$query

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


Return

(void)


Source

File: inventory-presser.php

		 */
		public function modify_query_orderby( $pieces ) {
			/**
			 * Count the number of meta fields we have added to the query by parsing
			 * the join piece of the query
			 */
			global $wpdb;
			$meta_field_count = count( explode( "INNER JOIN $wpdb->postmeta AS", $pieces['join'] ) ) - 1;

			// Parse out the ASC or DESC sort direction from the end of the ORDER BY clause.
			$direction             = $this->get_last_word( $pieces['orderby'] );
			$acceptable_directions = array( 'ASC', 'DESC' );
			$direction             = ( in_array( $direction, $acceptable_directions, true ) ? ' ' . $direction : '' );

			/**
			 * Build a string to replace the existing ORDER BY field name
			 * Essentially, we are going to turn '{$wpdb->postmeta}.meta_value' into
			 * 'mt1.meta_value ASC, mt2.meta_value ASC, mt3.meta_value ASC'
			 * where the number of meta values is what we calculated in $meta_field_count
			 */
			if ( 0 < $meta_field_count ) {
				$replacement = $pieces['orderby'] . ', ';
				for ( $m = 0; $m < $meta_field_count; $m++ ) {
					$replacement .= 'mt' . ( $m + 1 ) . '.meta_value';
					/**
					 * Determine if this meta field should be sorted as a number