## How to order posts by meta_value created inside loop?

Question

Inside the WP_Query, I’m trying to order posts by price.

The problem is that the price value is not manually defined inside an ACF or so, but it comes from an api call made while looping trough posts, like this:

<?php while ( have_posts() ): the_post();

$asin = get_field("asin");?> <h3><?php the_title(); ?></h3> <p><?php echo aawp_get_field_value($asin, 'price'); ?></p>

<?php endwhile; ?>


That means that the numeric value (the price) isn’t available before actually running \$the_query, so I cannot use something like:

'meta_key' => 'price',
'orderby' => 'meta_value_num',
'order' => 'ASC'


because "price" does not exists at that time.

I searched a lot but I didn’t find a solution to this. Maybe I need to order posts after the loop?
How would you do that?