Sorting the data called with WordPress Acf, API.
-
I use the advanced custom fields pro plugin on my wordpress site. I want to sort numerically from bigger to smaller, data which I got from API. I am receiving the data without any problems. But I could not sort.
<?php if( have_rows('g_pool' , 'options') ): ?> <?php while( have_rows('g_pool' , 'options') ) : the_row(); ?> <?php $name = get_sub_field('pool_id'); $o1 = file_get_contents('JSONADDRESS' . get_sub_field('pool_name') . '?api_key=' . $api); $pl1 = json_decode($o1); $d1 = $pl1->id; $a1 = file_get_contents('JSONADDRESS'. $d1 . '?api_key=' . $api); $player1 = json_decode($a1); $rank1 = $player1['0']->rank; $point1 = $player1['0']->leaguePoints; $tier = $player1['0']->tier; $ary = ARRAY($point1); RSORT($ary ); FOREACH ($ary AS $_point){ ECHO $_point.'<br>'; }
The sample json content I got from api is as follows:https://prnt.sc/vylsf6
As you can see there is a value called leaguePoints. In my codes above, I transfer the leaguePoints value I got from json to the point1 variable.
The screenshot you see below is my repeater content: https://prnt.sc/vylui6 (admin) Let me explain the pool name field. Users are registered with these names in the system where I receive data with API. That’s why I write the user name they registered in the system into this pool_name field. I get the user data by assigning the value entered in the field to the api url in the codes you see above.
And the result is as in the screenshot I shared below:https://prnt.sc/vyls9o (output)
I get results as I wrote from the admin panel. All I want is to sort the numbers in the variable point1 in descending order. Of course, this data is demo. Maybe hundreds of lines will be entered, so I want to use repeaters. Actually I can print without sorting. But the important thing for me is to print in order.
- The topic ‘Sorting the data called with WordPress Acf, API.’ is closed to new replies.