Inventory_Presser_Customize_Dashboard::vehicles_table_columns_orderbys( WP_Query $query )

vehicles_table_columns_orderbys


Description Description

Change the dashboard post query to sort based on a custom column we added.


Top ↑

Parameters Parameters

$query

(WP_Query) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-customize-admin-dashboard.php

	function vehicles_table_columns_orderbys( $query )
	{
		if( ! is_admin() || ! $query->is_main_query() ) { return; }

		$columns = array(
			'color',
			'odometer',
			'price',
			'stock_number',
		);
		$orderby = $query->get( 'orderby' );
		foreach( $columns as $column )
		{
			$meta_key = apply_filters( 'invp_prefix_meta_key', $column );
			if ( $orderby == $meta_key )
			{
	            $query->set( 'meta_key', $meta_key );
	            $query->set( 'orderby', 'meta_value' . ( INVP::meta_value_is_number( $meta_key ) ? '_num' : '' ) );
	            return;
			}
		}
	}