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 can I make the hero image full width, while keeping the contents below it contained, without the scroll bar appearing when viewing it?
- How to create dynamic value in WP_Query meta_query
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- Is it possible to add relation between meta_query and tax_query?
- mysql query order by
- Woocommerce: order posts by meta key
- How I can repeat 2 HTML templates in a WordPress Query?
- Modify query posts
- Get meta_value of a specific meta_key from all posts belonging to a specific custom type
- PHP – Loop custom post type categories within jQuery Tabs
- Use title of post as argument for query
- WP_User_Query and user posts
- pre_get_posts – editing query, tax_query
- Check if a post has term inside loop
- How can I comment comma-separated array values?
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- WP_Query by keyword OR post tag
- Custom query filter by ACF date custom field
- Grabbing taxonomy terms and inserting them into an array
- WP_Query returns no posts for category
- How do I add a relation parameter to my filter query?
- Order WP_Query results by meta key value in custom query
- construct complex queries with WP User Query
- Need help understanding this WP Query [closed]
- Searching by title, content and custom taxonomy
- How to retrieve certain number of images from a wordpress post?
- How do I fit WP_Query arguments into a function?
- Create a notification for post field
- Storing an array of objects related to each user
- Create one-use post dynamically, add to main query, do not insert post (user profile view)
- Using a Shortcode to List Posts from Multiple Categories
- How to display a list of posts in same child category as current post
- How to create a widget like this?
- WP_Query to get post on frontpage
- Does WP_Query ‘responds’ badly to empty arguments?
- querying posts with a custom status
- When listing child pages run out of memory
- How can I update post meta inside a WP_Query loop or the WordPress loop?
- Query by date from custom field
- Retrieving post meta array (attachment)
- problem with loop
- Printing a variable inside a custom WP_Query
- WP_Query->request has a limit
- Notice thrown when creating numeric pagination on custom query
- and tag not working
- WordPress Attachments with old images