Yeah, you can access that data using get_post_meta, remember that almost everything in WordPress is a type of a post, an audio
its a wp_attachment
type, you just need the ID
, also you can make a shortcode
, this is an example:
function my_audio_func($atts) {
$audio_id = $atts['id']; //we need an ID as attribute
//we get the audio and the metadata
$metadata = get_post_meta($audio_id, "_wp_attachment_metadata");
echo "<pre>";
var_dump($metadata);
echo "</pre>";
//we get the post object to get the URL of the AUDIO
$audio = get_post($audio_id);
$audio_src = $audio->guid;//for object values is like this is an object
//
$attr = array(
'src' => $audio_src,
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
//display the audio player
echo wp_audio_shortcode($attr);
echo "<br/>";
//display the metadata ARTIST
echo $metadata[0]["artist"];//for metadata like this is an array
}
add_shortcode('my_audio', 'my_audio_func');
in your post use it like this:
[my_audio id="198"]
it will show like this:
this is all the metadata keys, the info you can get:
array(1) {
[0]=>
array(16) {
["dataformat"]=>
string(3) "mp3"
["channels"]=>
int(2)
["sample_rate"]=>
int(44100)
["bitrate"]=>
int(128000)
["channelmode"]=>
string(12) "joint stereo"
["bitrate_mode"]=>
string(3) "cbr"
["lossless"]=>
bool(false)
["encoder_options"]=>
string(6) "CBR128"
["compression_ratio"]=>
float(0.090702947845805)
["fileformat"]=>
string(3) "mp3"
["filesize"]=>
int(458918)
["mime_type"]=>
string(10) "audio/mpeg"
["length"]=>
int(29)
["length_formatted"]=>
string(4) "0:29"
["artist"]=>
string(6) "MY_ARTIST"
["album"]=>
string(5) "MY_ALBUM"
}
}
if you want the caption or name, that would be in the post object:
object(WP_Post)#587 (24) {
["ID"]=>
int(198)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2017-09-26 15:54:30"
["post_date_gmt"]=>
string(19) "2017-09-26 15:54:30"
["post_content"]=>
string(38) ""My test audio"."
["post_title"]=>
string(35) "My test audio"
["post_excerpt"]=>
string(10) "MY_CAPTION"
["post_status"]=>
string(7) "inherit"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(35) "my-test-audio"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2017-09-26 17:36:59"
["post_modified_gmt"]=>
string(19) "2017-09-26 17:36:59"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(176)
["guid"]=>
string(97) "http://my_testsite.com/wp-content/uploads/sites/4/2017/03/my-test-audio.mp3"
["menu_order"]=>
int(0)
["post_type"]=>
string(10) "attachment"
["post_mime_type"]=>
string(10) "audio/mpeg"
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
i commented in the shortcode how you can access values in the object and in the metadata array.