Turns out, I was kind of wrong when I tried to get the largest ID. What I needed was to get posts by, and then to sort by, the order number itself! Here’s what I came up with:
$num_args = array(
'post_type' => 'my_store_order',
'post_status' => array('mystatus_1', 'mystatus_2', 'mystatus_N'),
'numberposts' => 1,
'meta_query' => array(
'my_clause' => array(
'key' => 'my_order_number',
'type' => 'numeric',
'compare' => 'EXIST'
)
),
'orderby' => 'my_clause',
'order' => 'DESC'
);
Also, since post meta is a string, I added ‘type’ => ‘numeric’ so when being sorted it would be treated as a number (1,2,10 vs 1,10,2)
This post helped me a lot