Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to get all file attachments which is not an image,
'post_mime_type' only accepts "any" or specific mime types,

How to grab all type of attachments, but images?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

WordPress has a function, get_allowed_mime_types, which will return all allowed types. We can filter this list and exclude any types containing image, then query for all remaining types by passing them as a comma separated list to post_mime_type. This may not be the most efficient way to do it, you may be better off filtering posts_where, but it'll work.

$filtered_mime_types = array();

foreach( get_allowed_mime_types() as $key => $type ):
    if( false === strpos( $type, 'image' ) )
        $filtered_mime_types[] = $type;
endforeach;

$args = array(
    'post_type' => 'attachment',
    'posts_per_page' => -1,
    'post_status' => 'any',
    'post_mime_type' => implode( ',', $filtered_mime_types )
);

$results = new WP_Query( $args );
share|improve this answer
    
It seems get_allowed_mime_types will be solve my problem, but that was very boring problem on wp –  Digerkam Feb 14 '13 at 13:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.