I am querying my posts and I am applying pricing orderby sorting filters below.
But my product_price_from
meta field contains a number which is inputted as various currencies. GBP, USD, AED etc. Because the suppliers are from different parts of the world.
I am live calculating this data into a single currency AED on the front end of the site using live currency rates. So that prices do not need to be updated every time there are currency changes.
Here is my sorting query example...
/**
* product archive filters
* @return array
*/
public static function filters() {
// determine our sorting filters
switch(self::$sorting) {
case 'price_highest':
$filters['meta_key'] = 'product_price_from';
$filters['orderby'] = 'meta_value_num';
$filters['order'] = 'DESC';
break;
case 'price_lowest':
$filters['meta_key'] = 'product_price_from';
$filters['orderby'] = 'meta_value_num';
$filters['order'] = 'ASC';
break;
case 'latest':
default:
$filters['orderby'] = 'date';
$filters['order'] = 'DESC';
break;
}
return $filters;
}
Because the number values all vary depending on currency rate, the orderby price results are not correct.
My question is there any kind of meta_key
filter that I can apply to fetched value before being applied to the query.
For example I would need to apply a function like this... toAED($post_id,$value,$currency);
to product_price_from
meta value in the query.
Is this possible with Wordpress query?