I edited the wp_playlist_shortcode
function at \wp-includes\media.php
WP core file, by adding
if ($atts['orderby']=='excerpt' || $atts['orderby']=='post_excerpt') {
function cmp($a, $b) {
return strcmp($a["caption"], $b["caption"])*(-1);
}
usort($tracks, "cmp");
}
before $data['tracks'] = $tracks;
line.
Basically after all tracks are generated into the $tracks
array and before this array is passed to the final array $data
, I intercepted the code and checked if orderby
parameter is set to excerpt
or post_excerpt
. If true did a usort
to sort array descendingly by using caption
as criteria. In playlist context, WordPress refers to excerpt
as caption
. If you need to be sorted ascendingly remove the *(-1)
within the cmp
function.
Thanks to the @Pat-J for suggesting usort
.