Query Order By Number Variable From API

admin2025-06-03  3

Trying to order the query by a number variable $total that is a storing an api containing a number. My goal is to output an ordered list with the number ($total) sorting the list. I've looked around for a few different examples but nothing seems to work that I've stumbled across.

<?php 
      $shortcode = get_field('shortcode_for_data');
      $url = 'api/?SHORTCODE=' . $shortcode;
      $obj = file_get_contents($url);
      $json = json_decode($obj, true);

      $amountTotal = explode( '.', $json[0]['AMOUNT'] );

      $total = number_format($amountTotal[0]);

      //($total is outputting a number like 12,345 with a comma)

      $output = new WP_Query(array(
                  'post_type' => 'output',
                  'posts_per_page' => -1,
                  'meta_key' => $total,
                  'orderby' => 'meta_value_num',
                  'order' => 'ASC'
                ));

      echo '<ol>';

      while($output->have_posts()) : $output->the_post(); ?>

       <li>
         <div><?php the_title(); ?></div>
         <div><?php echo $total ?></div>
       </li>

     <?php } wp_reset_postdata;?>

      <ol>

Goal (order by number):

Title Three 12,345
Title Two 11,345
Title One 999
Title Four 456

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748933959a314945.html

最新回复(0)