Commit 618a464f authored by Matheus Gimenez's avatar Matheus Gimenez
Browse files

Remove playlist dos resultados / garante ordenação por data de publicação

parent 6d710fde
......@@ -166,6 +166,7 @@ function video_playlist_callback($attributes = [])
$url = "https://www.googleapis.com/youtube/v3/playlistItems?" . $query;
} else if ($youtube_format == 'channel') {
$query_array['channelId'] = $youtube_id;
$query_array['type'] = 'video';
$query = http_build_query($query_array);
$url = "https://www.googleapis.com/youtube/v3/search?" . $query;
}
......@@ -189,6 +190,16 @@ function video_playlist_callback($attributes = [])
* e pega os primeiros videos de acordo com o maxResults.
*
*/
$result = json_decode(get_content($url, get_site_url()));
// ordena os videos
usort($result->items, function ($a, $b) {
$dataA = strtotime($a->snippet->publishedAt);
$dataB = strtotime($b->snippet->publishedAt);
return $dataA > $dataB ? -1 : 1;
});
$result->items = array_slice($result->items, 0, $max_num);
}
set_transient($cache_key, $result, 30 * MINUTE_IN_SECONDS);
......@@ -198,6 +209,7 @@ function video_playlist_callback($attributes = [])
}
}
if (!$result->items) {
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment