Inventory_Presser_Plugin::modify_query_for_max_price( object $query )
Modifies the $query to filter vehicles by prices for the Maximum Price Filter widget.
On This Page
Parameters Parameters
- $query
-
(object) (Required) An instance of the WP_Query class.
Return Return
(void)
Source Source
File: inventory-presser.php
* 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 * 1. Parse out the meta key name from $pieces['where'] * 2. Run it through INVP::meta_value_is_number */
Expand full source codeCollapse full source codeView on Github