I am trying to find ways to sort my loop from a numeric value(distance) that i can only get via a shortcode(by calculating custom field address). shortcode works, i successfully got the distance value but now i want to sort my data from closest distance to farthest.
i was trying to use usort, but i don't know how to execute it properly.
$loop = new WP_Query( $args );
function customCompare($Aint, $Bint)
{
$Aint = $distance;
$Bint = $distance;
return ($Aint < $Bint);
}
usort($loop->posts, 'customCompare');
while ( $loop->have_posts() ) : $loop->the_post();
$address = get_field('acf_address');
$distance = do_shortcode("[distance address='".$address."']");
im expecting to display my data from lowest distance value to highest but right now it doesn't do anything to my loop, just displays the default order. which means my code doesn't work. I would appreciate any help/suggestion