WordPress saves media library in the _posts
table – you’ll see post_type
of attachment
for media library items. You’ll notice a guid
value in the row, which is the media items default URL.
While unlink()
‘ing your file, you can make the file’s full URL. Then use that full URL in a simple database query ($wpdb
) stating WHERE guid = '$thefullURL'
. That will return the row, and you’ll be able to get the ID
of the media library item.
With ID
retrieved you can then delete it with WordPress’s wp_delete_post()
(which will delete from library and also a bunch of _postmeta
jargon)
Related Posts:
- Redirect to another page using contact form 7? [closed]
- 500 Internal server error wp_handle_upload_prefilter
- wp_handle_upload – specified file failed upload test
- Custom uploader – Upload files and save link into database
- How to displaying Custom image, text and default image logo from Redux Framework option panel
- can’t unzip file
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- How to Add text value in Automatically in this conditions?
- Checkbox show / hide output result
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- save_post_product action not firing
- How to upload large media file in chunks, without any plugin?
- Conditional delete metadata does not works
- How to get the custom field value using SQL query
- Unexpected add action function in WP plugin
- How to create admin setting for this small plugin
- Allow a particular user to access a particular plugin?
- admin_notices show after load completed
- Prevent WordPress from sending set-cookie http header
- How to copy the all WordPress media items to another custom plugin folder?
- Cookie value changes back to previous value after changing
- Change plugin descriptions
- How can we get this dynamically as this folder may not be by the same name always → wp-admin
- How use wp_insert_post and add og:custom tags?
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Access remote SFTP server via WordPress login?
- The Build menu theme is frozen with the wordpress theme
- Problem with checked box on wp car manager plugin
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Hide content for specific users with id
- adding dynamic/multiple slug values in ‘option_none_value’
- How can I translate something in my class constructor of my plugin in WordPress?
- Define global variable in theme file and call that variable in plugin file
- Why is my shortcode not working?
- WordPress rewrite rule depend on meta values not ids
- Rename a folder via HTML POST request
- How to change “Read More” text?
- How to translate to spanish wordpress hardcoded content/files?
- what functions to use to resize images and create DB metadata for them after/during upload?
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- update_post_meta is not working for me when I use e.preventDefault for update button
- insert multiple entries in database using a loop issue
- Displaying friend’s posts only
- Theme editor removes backslashes
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- How to create a dashboard for logged-in users with custom functionality? [closed]
- Creating a user ‘add custom field’ section
- How can I insert a record into a custom table from my custom form in my custom admin page?
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Plugin Hook: Get posts
- Saving an array to get_options
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- Plugin Breaking WordPress Login
- How to get site homepage from plugin?
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Doing action based on input from options menu
- Undefined variable _POST
- Help me with my first very basic plugin
- Load my plugin before cache
- How use Dynamic hyperlink on each wordpress post?
- Unable to show 4 products in a row
- How to fix ‘Call to undefined function do_settings()’ error?
- What is the source outline for a basic word press plugin?
- My wordpress website admin panel loads very slow, what can i do about that? [closed]
- Submit posts in two different post types with the same form
- wordpress select multiple options and illegal string offset ‘timeslot’ [closed]
- how to search through plugin in wordpress cimy-user-extra-fields?
- How to create post comparison in wordpress
- What can I do to customize a widget provided with this plugin? from where have I to start?
- Upload Image to desired directory through plugin
- How to add custom html to the Media > Attachment Details modal?
- Displaying Category Feature image on loop
- How to rename files during upload to a random string?
- Function not being called on form submit, only blank admin-post.php page
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How to override plugin function in code snippets WordPress
- How to make a Template page to show the information of different things Shop and Product page?
- How to create a “Most Popular” & “Latest” TAB in WordPress
- How to trigger plugin migration code when plugin updates?
- How to Save Category and Delete Category in same Function
- WordPress Throwing Deprecated Errors on its own Files
- public custom posts not showing in my wordpress plugin
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- plugin doesn’t retrieve data from database
- I want to allow certain file types on dokan upload files
- Accessing Correct Database to Create REST API Endpoint
- stop resize button for wordpress media
- Mixed results with is_page() WordPress function, when using $this, or self
- add_action() not working for admin
- REST API – filters not working inside plugin class
- Read page- or post-content across different builder-plugins
- How to make WordPress Plugin run on single specific Admin Page
- WordPress site server getting blocked due to resource abuse
- Error 400 Invalid “products[1].productId” Kinguin [closed]
- Plugin question, How to insert a colon in a value box
- Woocommerce attatch files and custom input meta to cart items and then to order