WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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;

$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

Your Answer


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.