Pretty much the solution is to include all mimes except images. WordPress has a nifty little function where it keeps all it’s accepted mime-types called get_allowed_mime_types() ( cleverly named ) which returns an Array() of mimes. All we need to do is get the difference between the returned array and the array of mime-types we don’t want in our query:
$unsupported_mimes = array( 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon' );
$all_mimes = get_allowed_mime_types();
$accepted_mimes = array_diff( $all_mimes, $unsupported_mimes );
$attachment_query = new WP_Query( array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => $accepted_mimes,
'posts_per_page' => 20,
) );
Related Posts:
- Count the number of images uploded on the website
- How to paginate attachments in a secondary query as gallery?
- get images attached to post
- query attachments of parent page if attachments of current page are smaller than …
- wp_query for displaying attachments with a tag
- WP_Query: attachment image in “full” size?
- wp_get_attachment_image not to get the post_thumbnaill
- How To Query All Attachment Images Found In Post Galleries
- Some images not being returned with wp_get_attachment_image
- Broken? WP_Query and “attachment” as a post type
- Is it possible to query all posts that don’t have an attachment?
- How to paginate wordpress [gallery] shortcode?
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- Getting attachments by meta value
- Get attachment by slug
- Get attached media only
- How to display images in related posts?
- post thumb nail
- WP Query search for attachments and their exact title
- Show selected images on top in Media Manager
- How can I query posts with newly uploaded images?
- Sorting By Custom Posts With Attachments
- Attachment changing page’s permalink – $post not resetting?
- How to fetch only media that was already attached to a post/page?
- How to do meta_query for attachments?
- Get attachment by meta_key value
- How to show optimized list of posts with all their attachment images
- Where to put meta Keys
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- Better wordpress attachment query than this
- Why having more than 10 clauses in WP_Query results in some outputs being dropped?
- wp_query get attachments in larger size
- Creating attachments archive in tags and categories
- How to add WordPress featured image via SQL
- Display all attached image of every post of custom post type and link to original post
- Ignore image urls in wp_query search
- Insert images into wordpress post with a query
- Find only those galleries with images
- How can I build a query that returns all attachments of a page and it’s children pages?
- get all images from the wordpress media library with link to the post they are associated with
- How to restrict add media library only to images of the same post family?
- how to get custom attachment url?
- Change database image location for transportability
- WP query retrieve the src of attached image
- Trying to use “Medium” featured image for custom post type on home page
- Query All Attachments and Order by Parent Publish Date
- Display images with same specific value?
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Using WP_Query to get attachment returns empty set
- Pull Instagram images into an existing loop?
- Loop issues when creating custom query for media uploader
- Give attachments an archive page, and exclude unattached ones
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- How do I query for posts by partial meta key?
- Display products from specific category in shop page
- wp_get_attachment_image_src and server path
- What’s the best approach for showing posts by A->Z order?
- Paginated pages are showing correct content but pagination links are not
- Query Posts but only return 1 from a custom taxonomy?
- Loop inside the loop
- WordPress search exact match
- wp_query, give first post different formatting
- Image still linked as attachment to page even though it has been deleted
- meta_query works locally but not on live server
- getting posts and number by specific meta value in multiple meta
- Issue to get wp_get_attachment_image with cmb2
- Retrieving list of a custom post type in a widget without using WP_Query?
- How to orderby meta_value_num with dollar ($) sign
- Order WP_Query by multiple fields, subtracting them from one another
- How can I convert results of WP_Query (of Custom Post Type, with Custom Fields) to JavaScript?
- How to order posts in wp_query by the user role (2 roles in array)
- Reset postdata to custom query in nested queries
- Add posts to WP Query object
- Does wp_get_attachment_image_src also work with non-image files?
- Query with meta_query and tax_query together not working properly
- meta_query fails to compare on values containing apostrophes
- Set front_page programatically after user login via query, while leaving site option alone
- Hook after attachment added and cropped
- How to Display Shortcode in the correct location, currently displaying before content after Page Title?
- Hiding carousel indicators if there’s only one post
- add_query_arg to compare and display events from a certain date
- WP Query get only 1 post (sticky, not sticky etc)
- Different image using srcset function
- Order post by modified date
- Redirect logged in users from a custom post type archive page if they don’t have a specific role
- Order 2 meta_queries differently in WP_Query?
- how to get dynamic data on wordpress from codeigniter?
- Rewrite rule pagination on different url levels
- WordPress Prevent 404 on missing custom post
- return wp query results in a shortcode
- confirm my booking with phone number
- Adding thumbnails for non-image attachments
- pre_get_posts redirecting
- Order by meta values
- Weird query with get_posts and WP_Query
- Adding arguments to WooCommerce Product Loop using AJAX
- How to hook the pre_get_posts filter via ajax call
- WP_Query and DES sort for Custom Taxonomy based upon a meta field?
- Help with showing text when something is entered in my search bar
- Get Related Posts by Tag if Tag is Empty Get Posts by Category