combining the two answer on this page, I found this worked.
$args = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => -1
));
$loop = new WP_Query($args);
while($loop->have_posts()) {
the_post();
$args2 = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image');
$attachments = get_posts($args2);
if($attachments) {
foreach ($attachments as $img_post) {
if( ((strpos($img_post->guid, '1.jpg')!== false) || (strpos($img_post->guid, '1.gif')!== false) || (strpos($img_post->guid, '1.png')!== false))){
$stuff = $img_post->guid;
wp_delete_attachment($img_post->ID);
}
}
}
} wp_reset_postdata();
Related Posts:
- Remove duplicate images from media library.
- Programmatically adding images to media library
- Upload images to remote server
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Separate Media Library for each user
- Why is wp_get_attachment_image_src not working with my custom size (add_image_size)
- Images dont show in grid view, but do in list view
- How can I hide media library images from general users?
- How to rename an image attachment filename using php
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- WordPress function: limit size, only jpg, jpeg, limit of uploaded files per account
- Cannot access the thumbnails of attachment images… Cannot find the reason
- Import Images from one self-hosted WordPress install to another
- Uploading images to Media Library fails with Memory Exhausted
- Why can’t I edit certain images from the WordPress Media library?
- Edit image preview is not displayed
- How can I autopopulate titles in the media library?
- Regenerate missing _wp_attachment_metadata
- Upload thousands of images to WordPress without plugin?
- How to make programmatic image upload generate thumbnail and sizes?
- Best way to strip character entities (%20 etc)
- Different upload path per file type
- Display latest 12 images from media library
- Images are randomly deleted from server
- Get full image array
- Bulk image rotation
- HTTP Error when uploading files above 7mb unless using GD Image Editor
- Consolidating two websites into one, but migrated images not appearing in Image Library
- wordpress media library shows empty images
- How to order images in a post in WordPress 3.3?
- unattached media files that should be attached
- Bulk edit of EXIF data for jpeg images uploaded in the media library?
- offload media to external services [closed]
- How to upload images in a specific folder using API
- AJAX – save an $_FILES picture in media library
- In Wordress one author can not see the other’s author uploaded images through media library
- How to open default wp image editor screen dynamically?
- How to prevent WordPress scaling large images down
- Searching for any images in media library displays “no media found”
- How to get file URL from media library
- Change media URL (images)
- Alter image meta fields in the Media Library
- Add custom text in the media library image meta area
- How to add images to a post without inserting them into the content area of the post editor?
- Uploaded images not displaying in network site
- What happened to the media manger?
- Why does WP allow to view and media item as a page
- How to limit the number of images displayed in the media window?
- Images are not showing up in “Uploaded to this post”
- Get images attached to a specific page
- Images don’t update after being edited
- Is there a way in WordPress to convert images to WebP without a plugin?
- Change Image folder Locations
- Rebuild thumbnails via WP Cli – how?
- Images not showing in media grid view (but showing in list view)
- Some Images Disappeared from Media Library?
- are unattached media files a problem?
- WordPress Attachments with old images
- How to get the title of the random images from media library?
- Large image not showing dimensions in Media Library
- Disable image rename on upload
- Function to grab specific image IDs from media library.
- Fetching uploaded images using Link URL
- How can i sorting and display image order by siz in media library?
- WordPress append -1 to the image name
- Custom Image Widget
- Media Library Cleanup A Thought Exercise
- Do I need to re-register all my images in the media library after a migration?
- Could creation of various image sizes cause slow form submission response?
- imported post image as normal image instead encoded image
- Post-processing of the image failed
- still need help-images inside wp-content/ uploads/ are not showing up in my media library and uploaded using FTP protocol
- The image keep redirect to my previous URL after I moving my site
- WordPress Link To Image Missing Dropdown
- After moving a site to new hosting, not all images are showing in media library
- Blank image thumbnails in media library
- Broken images in media library
- Images are not getting uploaded
- Unable to delete images in Media Library
- Edit image itself
- Change the image for a certain URL
- Assign one featured image to multiple posts?
- Some images don’t get linked when setting link-to to media-image
- Missing Images in Uploads Directory (Server Only)
- How do I embed an image at actual size?
- Image media upload problem in page editing modus?
- Transfered live site to new server and images are not showing
- Limit files uploaded per folder
- My image rotate 90 degree
- How do I change a Themes Header Image?
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- Remote Image (from URL) as Media Library element
- WordPress can’t get image url but both the attachment and the actual file are there
- Why some images are not allowed to be edited only for thumbnails?
- My subdirectory sites images (except webP) are throwing to 404 page even they are exist
- What does WordPress media uploader do to image files on upload?
- Media Library shows default image instead of image preview
- How can I use an image from an external source without uploading it to the media library
- Images have dissapeared from media library and site