I'm trying to sort my WP_Query by a meta key but the problem is that the meta key is a string and not a number. What i want to do is somehow remove the letters from the string and then order by this value.
For example, 'meta_key' contains letters before the number like FOR04. Is it possible to somehow remove the letters from this within the $args?
Can i do something like this?
'meta_key' => preg_replace('/[^0-9]+/', 'test_2')
$args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'key' => 'test_1',
'value' => $post->ID,
'compare' => 'IN',
),
),
'meta_key' => 'test_2',
'orderby' => 'meta_value_num',
'posts_per_page' => -1
);
I've tried this method but it's not sorting them correctly..
$args['meta_key'] = preg_replace('/[^0-9]+/', '', 'db-id');
$args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'key' => 'court',
'value' => $post->ID,
'compare' => 'IN',
),
),
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => -1
);