Created
February 14, 2020 20:29
-
-
Save marco-van-zomeren/c88c8c4b520ae5237d014ecc277abdc7 to your computer and use it in GitHub Desktop.
Get audio url from post attachment WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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