Leave a Reply

2 comments

  1. Try meta_value_num

    'meta_key' => 'metadata1',
    'orderby' => 'meta_value_num'
    

    Add these 2 parameters to $args. This does the sorting considering metadata1 as numeric

  2. Also, if you can’t get this to work with get_posts, I’d recommend switching to WP_Query.

    As Mridul said above, to sort based on numbers, you need to specify the 'meta_value_num' to 'orderby' parameter. However, I’m not certain that you can do this with a standard get_posts() call.