Like it says on the tin - Im trying to create a list of post attachments that includes everything except say audio, which I'll feed into a player instead.
- The filter needs to be generic: 'audio' not 'audio/mpeg'.
(For some reason if ( $mime !== 'audio/mpeg' ) will filter out valid mp3 files –– weird.)
So the following dosen't work:
$children = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment' ) );
if ( !empty( $children )){
foreach ( $children as $attachment_id => $attachment ) {
$mime = get_post_mime_type($attachment);
$url = wp_get_attachment_url( $attachment->ID, false );
if ( $mime !== 'audio/mpeg' ) {
$content_attach .= '<a href="' . $url . '" download="' . $url . '"> ' . $title . ' | ' . $mime . '</a>';
}
}
}
echo apply_filters('the_content', $content_attach );
Further listing every audio mime type like so: if($mime !== 'audio/mpeg' || $mime !== 'audio/ogg') etc will still leave out those crazy mp3 files.
What does work is:
$children = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'audio' ) );
which will return all the attached audio types in one go - great my player can handel it.
Now I need to omit everything that isn't audio and list it.
Does anyone have any ideas?
and thanks again for your help and experience. . .
if($mime !== 'audio/mpeg' || $mime !== 'audio/mpeg')is the same as »If: it is NOT AudioMpeg OR it is NOT AudioMpeg« ... doesn't make much sense asking the same twice, eh? – kaiser Apr 11 '12 at 22:27if($mime !== 'audio/mpeg' || $mime !== 'audio/ogg')–– I've corrected it. – orionrush Apr 11 '12 at 22:39