Try this one:
Its working in mine.
$attachment_mime = wp_check_filetype(wp_get_attachment_url($post->ID) );
if ( $attachment_mime['type'] == 'audio/mpeg') {
echo 'this is audio';
}
else {
echo 'this aint audio';
}
Thanks.
Question
I am trying to create a if else statement for checking if the attachment is an audio file or not.
Could anyone assist in this please. I am using the wordpress get_post_mime_type function
if (get_post_mime_type($post->ID) == 'audio/mpeg') {
echo 'this is audio';
}
else {
echo 'this aint audio';
}
Any help would be greatly appreciated. This is inside the wordpress loop.
Solution
Try this one:
Its working in mine.
$attachment_mime = wp_check_filetype(wp_get_attachment_url($post->ID) );
if ( $attachment_mime['type'] == 'audio/mpeg') {
echo 'this is audio';
}
else {
echo 'this aint audio';
}
Thanks.
OTHER TIPS
you can try this one also.
File Type: <?php echo $attachment->post_mime_type; ?>
or
<?php echo get_post_mime_type(); ?>
Thanks