I've succesfully pulled in an array from an API for my client's podcast and can display the values in a foreach loop in the order they are already ordered in.
The issue is, I want to list the episode titles by most played not by most recent.
Here's my code so far...
function buzzsprout_top_picks() {
$url = 'XXXXXXXXXX'; // api url goes here
$data = file_get_contents($url); // put the contents of the file into a variable
$episodes = json_decode($data); // decode the JSON feed
$i = 1;
foreach ($episodes as $episode) {
$plays = $episode->total_plays;
echo '<p>';
echo $i . '. ';
echo $plays . ' <a href="">' . $episode->title . '</a>';
echo '</p>';
if ($i++ == 5) break;
}
};
When I var_dump $episodes I get the following for each of the episodes (currently from most recent to least recent)...
array(51) {[0]=> object(stdClass)#17351 (19) {["id"]=> int(8672400) ["title"]=> string(62) "The University of Life Together With Lala Sol & David Plimpton" ["audio_url"]=> string(106) "https://www.buzzsprout.com/821509/8672400-the-university-of-life-together-with-lala-sol-david-plimpton.mp3" ["artwork_url"]=> string(137) "https://storage.buzzsprout.com/variants/z6tadwm96ym3gkjbzmomwnlgonzy/8d66eb17bb7d02ca4856ab443a78f2148cafbb129f58a3c81282007c6fe24ff2.jpg" ["description"]=> string(1322) "
I don't often interview couples but with these two I had to make an exception, meet Lala Sol & David Plimpton, a beautiful couple that are travelling the world helping people integrate into a more holistic way of being.
We crossed paths earlier this month, they have a beautiful positive energy that radiates out from them as a partnership, it immediately struck my curiosity and we got chatting.
They've been together over 6 years now, David is from the United States and Lala from Columbia, they met in college and have been together and travelling the world since.
In this chat we discuss how they met and built the outstanding relationship that they have now. The challenges they went through and how they navigated through these.
We talked into the work that they do with their clients and some of the key values they share with them. What are the main lessons they've learned through their wellness journeys.
I really hope you enjoy this and get great value from it. Let me know your feedback either via instagram or my site & if you want to connect in with them from here, you can find them via:
Lala's Instagram: https://www.instagram.com/lala.holistic/
David's Instagram: https://www.instagram.com/tikitango/
" ["summary"]=> string(220) "I don't often interview couples but with these two I had to make an exception, meet Lala Sol & David Plimpton, a beautiful couple that are travelling the world helping people integrate into a more holistic way of being. " ["artist"]=> string(11) "Jamie White" ["tags"]=> string(115) "The University of Life, Lala Sol, David Plimpton, love, jamie white, university of life, holistic living, wellbeing" ["published_at"]=> string(29) "2021-06-10T13:00:00.000-04:00" ["duration"]=> int(3631) ["hq"]=> bool(false) ["magic_mastering"]=> bool(true) ["guid"]=> string(18) "Buzzsprout-8672400" ["inactive_at"]=> NULL ["episode_number"]=> int(50) ["season_number"]=> int(1) ["explicit"]=> bool(true) ["private"]=> bool(false) ["total_plays"]=> int(59) }
I've looked at different ways of sorting the array but I'm unsure what to do next.
Your help would be appreciated! Thank you.