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