如何在 WordPress 中显示嵌入音频文件的标题

How to show the title of the embedded audio file in WordPress

audio_list(get_the_content())

function audio_list($data){

$content    = strip_tags($data);
$audiolist  = explode("[/audio]", $content);
$audiolist  = array_filter($audiolist);
return $audiolist;

}

现在我正在使用一个自定义函数来剥离音频 url 并将文件名与 url 分开,并将真实文件名显示为我站点中的音频名称。我需要将真实姓名更改为媒体标题。我怎样才能做到这一点 ??在 Word Press 中,嵌入式播放器媒体 ID 不可用。在批量上传的情况下,媒体不与任何 post 相关联,因此 parent post 附件概念也不起作用。还有其他方法可以获取媒体标题吗??

先将上传的音频文件获取为数组

$args = array(
        'post_type' => 'attachment',
        'post_mime_type' => 'audio',
        'numberposts' => -1
    );
    $audiofiles = get_posts($args);

创建一个匹配文件 url 的

的 if 条件
foreach ($audiofiles as $file)
{
  $urls = wp_get_attachment_url($file->ID);
  if($urls == 'url from the content'){
      $title = $file->post_title;
  }else {
      $title = 'file real name';
  }
}