是的,你可以使用get_post_meta, 记住,WordPress中的几乎所有内容都是一种帖子,一种audio
它是一个wp_attachment
类型,您只需要ID
, 您还可以shortcode
, 这是一个示例:
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\');
在您的帖子中,请这样使用:
[my_audio id="198"]
它将显示如下:
这是所有元数据密钥,您可以获得的信息:
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"
}
}
如果需要标题或名称,则应在post对象中:
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"
}
我在shortcode中评论了如何访问对象和元数据数组中的值。