I have a meta box where a 'Case Result' CPT can be assigned a monetary value (e.g. $60 Million). I need to convert this into a decimal number for use as the meta_key
in WP_Query
.
I understand how to do the reverse (https://www.php.net/manual/en/function.number-format.php#89888), but want to know if there's a reasonable approach to taking a '$60 Million' string and converting it to '60000000'.
My current query is below, which is re-run across multiple 'Attorney' pages (hence the $attorney_name
for terms
) to show the only cases they were responsible for. I'd like to order these posts by their monetary value in descending order, but I'm aware the current config (meta_type
etc) won't work with the value in it's current string state. Any advice would be massively appreciated.
// Configure query
$query = new WP_Query( array(
'posts_per_page' => -1,
'post_type' => 'case-result',
'tax_query' => array(
array (
// Filter CPT's to display by taxonomy
'field' => 'name',
'taxonomy' => 'case-result-attorney',
'terms' => $case_result_attorney$attorney_name,
)
),
// Sort CPT's by meta
'meta_key' => 'case_claim_value',
'meta_type' => 'NUMERIC',
'order' => 'DESC',
'orderby' => 'meta_value_num',
)
),
) );