So, in the previous question I asked, previous question
and didn't get any answer, so I have an idea from the previous question of mine, to make it more compact, so this what I thought, is it possible to call a function in a SQL query?
So this is the condition I had now, I have a function to convert price using API, and I want to sort it by price but the problem is each product have different currency.
Ex:
Product A - USD 1,800
Product B - IDR 1,900,000
Product C - EUR 1,000
So if I just sort by the price from the database, it'll messed up, because the currency are different. So I want to make the all the data from mysql is automatically changed to price in USD (default, here is when the function needed)
$args=array(
'meta_key' => 'monthly',
'meta_value' => 'yes',
'posts_per_page' => 12,
'paged' => $paged
);
$mam_global_fields = ', price.meta_value'; // I want to change this
$mam_global_join = "
INNER JOIN " . $wpdb->postmeta . " AS currency ON (" . $wpdb->posts . ".ID = currency.post_id AND currency.meta_key = 'monthly_currency')
INNER JOIN " . $wpdb->postmeta . " AS price ON (" . $wpdb->posts . ".ID = price.post_id AND price.meta_key = 'monthly_price')
";
mam_global_orderby="total_price ASC";
...To something like this, but I don't know how to do this, but it's something like this or some way similar like this or my previous question
$mam_global_fields = ', price.meta_value, '. convert_price('price.meta_value', 'currency.meta_value') . ' AS total_price';
I appreciate any kind of helps or ideas
I appreciate any kind of helps or ideas. So if someone wants to write the codes for me, of course I'll appreciate it.