If you want to delete files from the Media Library, then you need to delete both the database entry (attachment post) and the actual file (files to be more precise as there might be one or more scaled versions of the same image file depending on your setup).
You can do these both actions for example with wp_delete_attachment()
, https://developer.wordpress.org/reference/functions/wp_delete_attachment/, which of course requires you to first know the IDs of the attachment posts, which have -1.jpg on the file name.
To find these IDs you’ll need to query the yourprefix_posts
database table. You’ll need to use $wpdb
as you need to query the guid
column to find attachment posts with the matching file name as the file path/url is stored in that column – if I remember correctly.
Related Posts:
- Change the default-view of Media Library in 3.5?
- Get All Images in Media Gallery?
- List of available events for wp.media
- WordPress 3.5 attachment_fields_to_edit and media_send_to_editor
- Bind event on Media gallery elements WordPress
- How to upload an image in the plugin’s options page
- WP 3.5 media uploader API set selected item
- Remove the columns in media library
- How to save attachment data?
- Using WordPress as a document library
- How to enlarge thickbox media library iframe?
- How to modify Media Library images
- Inserting a Download Link in the Quick Edit Actions of the Media Library?
- How do I remove the entire Media section from the main WordPress navigation without just hiding it?
- Change default screen option value for media items per page (in media library)
- Making the Add Media Link URL into a checkbox
- Add tab on new media library
- Is there any way to add images to the Media Library through a path on the server?
- Media Library page super slow, loading up full quality images
- Show ids of displayed media library items
- How can I use the TinyMCE editor for the description field on a Media item?
- how to download all media files into my computer
- Add image to media library from URL in uploads directory
- How does the media library determine if a PDF file has preview images?
- resize from small images to large
- Bulk Import files on Media Library from CSV
- How can I make the Uploaded field editable for Media Library?
- Display only my own files/images in media library
- “Insert Into Post” For Custom Button
- Display image file size in media library
- Media_handle_upload with custom upload folder?
- remove_menu_page breaks “Add media”
- is there any hooks or action to fire function of insert into post in media library?
- Organize media uploads in folders – I have a physical access to (my) server
- Pulling images from a subdomain
- Slow/Not Working Media Library Search
- Get image URL from media library “insert from url”
- Sorting Media Library by Author Name
- Media gallery: remove “insert into post” button keeping “Insert gallery” button
- Media Content disapeared after upgrade WP core to 3.5.1
- change video icons to selected thumbnail?
- how to remove thumbnail and LiteSpeed Optimization column in media library list-view?
- How do I migrate blog post images from one domain to a new one?
- Manipulate an image before saving or after to the media libary
- wp_get_attachment_image_src returns the wrong image
- Get the largest image based on a thumbnail in a URL
- Intersept image upload and generate retina image from source
- Image file names with a space in them
- Crop image with full width
- Change Media Library thumbnails for non-image files to include the post title instead of the filename?
- attachment media-template data model (data.size.url)
- the_post_thumbnail(“size”) returns same image for all sizes except thumbnail
- How do you alter the default WordPress thumbnail?
- Media Library, hook on delete user action
- Create a User Role with permissions to only upload files to the media library?
- Adding Alt Tag Column to Media Library List
- High CPU load when loading images in media library
- How to modify the attachment info text on gallery tab or media page?
- Add media button always inserts media on the next wp_editor instance when created dynamically
- Images are displaying as blank images
- Is it possible to share WordPress media files among different domains?
- Is it Helpful to transfer all media library to another host? [closed]
- How to manage a music library in wordpress
- Media library on another server?
- How to edit a deleted image gallery?
- WordPress lowers image quality
- WordPress ACF delete image from media library
- image not found in media library
- Windows Live Writer inconsistent with Media Library
- Is there a way to programmatically pass a category to the Media Library selector?
- WordPress Media Import, images not in Media Library
- Want to sell images online on wordpress but slow image loading issues
- images inside wp-content/ uploads/ are not showing up in my media library and uploaded using FTP protocol
- add_image_size() in custom theme is not generating and saving any thumbnail
- Change thumbnail size for Media Library
- Adding Facebook Open Graph Code does not work for Media Library Attachment Pages
- Update WP Media Library image unattended
- Uploads folder only showing files up to the letter “P”
- WordPress not using edited image
- How to display the date a directory folder on ftp was modified
- Moving wp from a server to another, with different administrator
- How to access media library?
- Create gallery doesn’t show uploaded images
- Media Library not showing images when adding to Posts (but retrieving image info via ajax)
- WordPress 3.5 Media Manager – Change loaded image Size [duplicate]
- Change the default-view of Media Library in 3.5?
- How use Videos from another directory?
- bulk deleting empty items in the media library
- Media Manager 3.5 custom options
- Remove (Unattached) Attach from “Uploaded to” in Media Library
- Uploading pictures to the Media Library: “Specified file failed upload test.”
- WordPress Media Library
- Create media library feed
- Broken image links in media library after restore
- Store images and videos category wise and fetch them in json format
- 2 or more WordPress instances (Live vs Staging Test site) –> access 1 uploads.domain.com — images holder – see images in Media Library
- media library contains corrupt doubles
- How can I change the page title of PDFs opened from a WordPress link which use the browser’s viewer?
- Files showing in link but cannot be found in the upload directory
- Block non logged in users from accessing the media library