Skip to content

Instantly share code, notes, and snippets.

@marco-van-zomeren
Created February 14, 2020 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marco-van-zomeren/c88c8c4b520ae5237d014ecc277abdc7 to your computer and use it in GitHub Desktop.
Save marco-van-zomeren/c88c8c4b520ae5237d014ecc277abdc7 to your computer and use it in GitHub Desktop.
Get audio url from post attachment WordPress
<div class="audio">
<?php $audio = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'audio' ) ); ?>
<?php if ( empty( $audio ) ) : ?>
<?php else : ?>
<?php foreach ( $audio as $attachment_id => $attachment ) : ?>
<div class="player">
<audio controls>
<source src="<?php echo wp_get_attachment_url( $attachment_id, 'full' ); ?>" type="audio/mpeg">
</audio>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment