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
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- How to add classes to images based on their categories?
- Get posts by meta data OR title
- How do i upload an image and return the image id?
- page was loaded over HTTPS, but requested an insecure image
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- How to change _wp_attachment_metadata specific value in SQL?
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Add custom search results to main WP search [duplicate]
- What is the difference between RELATION “AND” and “OR” in TAX_QUERY?
- Query Set Order By Author
- SQL Query inside Widget
- How can I pick a single post from the latest 3?
- WP_User_Query unable to retreive all user at once
- Hide Administrators From User List except current user (administrator)
- Display attachment resolution size
- Custom Query num_rows returns wrong amount
- How to figure out redirection and contents in hybrid solution containing word press content and legacy code (ASP.net)
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- Most commented post showing 2 records
- Category ‘pad_counts’ & ‘parent’ conflict
- How to exclude Sticky from Recent Post?
- Display if author page is author page of current user
- get_query_var always returns the default value
- Modify WP_Query using pre_get_posts but only for frontend query?
- parse_tax_query causing Navigation Menu To Disappear
- the_post_thumbnail do 2 queries. How to optimize
- Creating ‘posts page’ loop based on the page itself
- Use full size images in a specific gallery
- How to get pages of parent (non-recursive)?
- WP_Query and pagination AGAIN?
- Can’t get term id for category archive
- Combine query in WP_User_Query()
- Nearby locations using Advanced custom fields, maps?
- How to get_comments() ordered by date and parent?
- WP Query filters active on wrong query
- Not able to fetch woocommerce variation sales products for particular category products
- Global page ID variable empty error
- Gather same custom field values in one value in a select tag with wp_query
- WP Query with sticky posts and tax_query
- Incomplete attachment page
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- Query posts by custom fields
- WordPress pagination returns the same posts
- wp_query, calculate with two dates when ‘key’ is text format
- Use value from meta key array for use in WP_Query