Good code. I think you could simplify by making direct SQL queries instead:
-- Featured Images
SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = '_thumbnail_id';
--> $thumbnail_ids
-- Header Images
SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = '_wp_attachment_context' and `meta_value` = 'custom-header';
--> $header_ids
Also, with your method, I think that if you call WP_Query with suppress_filters => true
(or use get_posts()
instead; it suppresses filters by default) you can avoid having to remove your own filter.
Related Posts:
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- How can I bulk delete media and attachments using WP-CLI?
- Edit image / Delete image link
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Unattaching unlinked images
- Show Post ID in “Find Posts or Pages” box in Media Library?
- Gel all image from certain post type
- Can i hide the attachments from media which I uploaded from front end?
- Get the attachment URL on single.php
- Perform a custom (bulk) action in media view
- How to retrieve alt attribute for an attachment (uploaded image)?
- Where does the gallery shortcode gets its attachments from?
- Control attachments menu order with jQuery Sortable
- Is it possible to share media files between multiple WordPress sites?
- Open the Attachment Details popup
- Proper use of wp_get_attachment_image?
- how to get random media id from media gallery
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- Get an image from the media library. Struggling with the code?
- Media Library Mess After FTP … /uploads
- Media item permalink goes to source file instead of attachment.php
- wp_get_attachment_image_src calling wrong location
- Removing images deleted from uploads folder, from Media Library
- WP media attachment location vs permalink
- Removing delete permanently button in uploading files media
- Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?
- How to remove attachments from main query via pre_get_posts?
- Is there a way to add Reattach and Unattach links in image gallery?
- How to retrieve images contained in a post
- How to save media-form on custom tab
- Bulk delete media by year
- Media library upload hook
- How To Retrieve An Image Attachment’s Alt Text?
- How to get attachment file name not attachment URL
- Custom collection in media manager?
- How to cleanly delete attachment but retain original file?
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- How could I add button next to “edit image” button in “Attachment Details”
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- get post attachments of a particular size
- How to save custom fields for attachments
- attachment url rewrite
- Get the title and URL of the attachment parent post
- Confused with attachment mimetype order
- query attachment images … if no attachments -> get attachments of parent page?
- Replacing with(out) regex link to attachment by links to files
- Getting attachment images is cloning some of them
- rename attachments based on parent-post-title on upload
- Rename attachments during upload no matter what filetype
- Link all WordPress images size
- Contact Form 7 Data As Attachment [closed]
- Displaying Post Attachment(s) at Top of single.php
- Detach an image from a page using php
- Get the path of the first attached media (single.php)
- custom admin thumbnail for videos, not getting post’s id?
- Custom Gallery HTML only working when images are attached to post/page
- Image Gallery Numbers for 3.5
- How do I link an image to the post it is attached to?
- How to delete a custom file from upload directory when deleting its post
- How to filter a post in the Tag Cloud widget, using tags of a media library image attached to the post?
- Query to only return the 2 newest post attachments (images)?
- Clean up images, delete unused image sizes attached to a post type
- What is the best way to store thumbnails for a non-image attachment?
- problem in uploading attachment to custom directory
- Add attachment for all images in post
- What will happen if I delete all my attachment type posts from database?
- filter get_children to return all mime types EXCEPT ‘x’
- Update media library image shown in “attachment details” when using wp_insert_attachment to add item to the media library
- Weird string offset errors when displaying post attachments
- the_time() returning wrong date/time (way in the future)
- Add audio attachment link to RSS
- Links to my uploads went crazy
- hide attached images of a post
- How to add a caption to an image attachment in a file list?
- Undoing define( ‘UPLOADS’, ”.’files’ ); to repoint to “wp-content/uploads” folder
- Upload image and assign it’s id to post
- Possible to add “Even/Odd Classes” to image attachments via wp_get_attachment_image?
- Can’t sort get_posts by post_mime_type
- How can I rewrite old attachment URLs?
- All images on one line for each post
- How to list “invisible” Auto Drafts?
- How to add media from front-end to an existing post and edit file title
- Auto delete content in specific folder inside media library
- How is it possible that a gallery doesn’t have attachment ids?
- Display audio file in audio.php
- Display setting ‘size’ not available in image settings modal
- Attachment file display link text
- Get video attachment ID and display length
- missing attachment are showing as 404
- controlling whether upload is attached to post or not
- How do I add Facebook OpenGraph meta tags for attachments in the header for a custom theme?
- Add link to attachment for old posts
- Drupal 6 to WordPress migration – media attachments
- Move caption in on attachment page
- Change attachment inside the_content using filters
- No attachments on contact form 7
- wp_mail attachment not working in wordpress