最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to get a post's attached media (audio) ID and insert it into rtmedia shortcode

programmeradmin0浏览0评论

I am working on a personal project that is set up in a way that each post will have only one media file attached (wav audio) and no imagery or other media at all. I am using rtmedia to transcode the uploaded wav file to mp3 and have the mp3 version playable in the browser with the default WordPress audio player.

I've uploaded an audio file that was given the media ID of 6, and shows up fine when I just hard code the ID for testing into the shortcode using

<?php echo do_shortcode( '[rt_media attachment_id= 6]' ); ?>

But I am not entirely sure of the syntax I would need to have the media ID change depending on what post it was attached to.

Something like the following, but doesn't work, nor did I really expect it to.

<?php 
$values = get_attached_media( 'audio' );
echo do_shortcode( '[rt_media attachment_id= '. $values[0] .']' );
?>

I'm not a coder, so please forgive my sloppiness.

发布评论

评论列表(0)

  1. 暂无评论