Inventory_Presser_Plugin::change_order_by_for_odometer( string $orderby, object $query )

Removes commas from the meta value used in the ORDER BY of the query so that odometer values can be sorted as numbers instead of strings.

Parameters Parameters


(string) (Required) The ORDER BY clause of a database query.


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

Top ↑

Return Return

(string) The changed ORDER BY clause

Top ↑

Source Source

File: inventory-presser.php

	public function change_order_by_for_odometer( $orderby, $query ) {
		 * Changes
		 * ORDER BY wp_postmeta.meta_value+0
		 * to
		 * ORDER BY REPLACE( wp_postmeta.meta_value, ',', '' )+0
		global $wpdb;
		return str_replace( "$wpdb->postmeta.meta_value+0", "REPLACE( $wpdb->postmeta.meta_value, ',', '' )+0", $orderby );