Try this:
function delete_attachment() {
$id = $_POST['att_ID']; // the attachment ID
// Deletes the attachment (and all of its custom fields or meta data; e.g.
// `photo_order`). The `true` bypasses the trash.
$att = wp_delete_attachment( $id, true );
// Deletes all custom fields named `vid_pix` where the value (`meta_value`)
// is the attachment ID (i.e. `$id`).
if ( $att ) {
global $wpdb;
$wpdb->query( $wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = 'vid_pix' AND meta_value = %s",
$id
) );
}
die();
}
Related Posts:
- Meta keywords and descriptions plugin for manually editing meta for each page/post
- Display info from custom fields in all images’ HTML
- copy attachments to another post type and change attachment url
- Save attachment custom fields on front end
- Insert attachment ID in custom field from media uploader
- Custom field not updating when value is empty
- Let’s Create Custom Field Template Documentation
- Best way to achieve multiple links in a post title
- When post is updated, custom metadata in text area field is overwritten
- Adding custom fields to images
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- Adding thumbnails for non-image attachments
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- what is the correct way to compare dates in a WP query_posts meta_query
- Can I exclude a post by meta key using pre_get_posts function?
- Add validation and error handling when saving custom fields?
- Validating Custom Meta Box Values & Required Fields
- Is there a way to set default custom fields when creating a post?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Difference between meta keys with _ and without _ [duplicate]
- Remove Dimension from wp_get_attachment_image
- Correctly delete posts with meta and attachments [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- What is the index [0] for on post meta fields?
- What is “meta_input” parameter in wp_insert_post() used for?
- How to enable revisions for post meta data?
- The “_encloseme” Meta-Key Conundrum
- Best way to programmatically remove a category/term from a post
- Using get_post_meta with new_to_publish
- Custom field metabox not showing in back-end
- So much data in postmeta
- Add custom objects/entities to WordPress
- explode array within shortcode
- Can I count the number of users matching a value in a multiple value key?
- How can I append custom data to images in the editor?
- Getting attachments by meta value
- When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
- How to hide meta box values from custom fields list?
- Auto sort the wp-admin post list by a meta key
- Adding another state (spam, reject, approve) to wordpress comments?
- get_post_meta() unserialize issue – returns boolean(false)
- What is the advantage of the wp_options design pattern?
- How can I remove fields in the attachment editor?
- Storing meta fields multiple times OR once with multi dimensional array?
- Allow user to create instances of custom field
- display specific custom fields
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- Saving Custom Field in Attachment Window in WordPress 3.5
- Edit Custom Database Tables in WordPress
- Add custom field to media attachment image attribute in post editor
- Filter results with custom field values and dropdown
- Add multiple images to a page sidebar
- passing argument to get_template_part() or a better way to code
- Is it possible to store arrays in a custom field?
- Get updated meta data after save_post hook
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- Save HTML formatted data to post meta using add_post_meta()
- Making a configurable field translatable
- How to set a default meta value for custom field
- importing data from non-wordpress mysql db
- Is there a way to do multiple ordering on a multiple meta_query?
- Check before publishing, if already exist post with current custom field value
- Add custom field to image editor
- How to customize default wordpress editor?
- Create meta boxes that don’t show in custom fields
- Transients vs CRON +Custom Fields: Caching Data Per Post
- Unable to save datetime custom meta field using update_post_meta() function
- Up/Down voting system for WordPress
- How to save custom fields for attachments
- post meta data clearing on autosave
- Custom Fields Bulk Edit
- Custom Page Template [closed]
- How to make custom comment fields required and message field not required
- Create custom field on post draft or publish?
- Ordering posts by anniversary using only day and month
- Problem in custom meta boxes
- get_post_meta fields don’t show up on posts page
- Update meta values with AJAX
- How to show custom field’s value under post/page title in wp-admin
- Multiplile values checkbox or select in custom meta box
- Adding Properties to User Profile and Displaying in List
- How to break meta values into different items and avoid duplicates?
- Cannot edit post meta fields with rest API
- How to use pagination with get_post_meta
- Copying Custom Meta Values from existing post to a duplicate post
- How do I read the value of a custom field of the page?
- How to get custom field image url of specific size
- Add a post meta key and value only if it does not exist on the post
- Move value of one custom field to another
- Order posts according to user defined order for meta values?
- Displaying posts with only upcoming dates according their custom field date value
- Custom fields to save multiple values
- Custom fields: In what order are they saved into the DB?
- Function to change meta value in database for each post
- Get a post_id where meta_value equals something in a serialized meta_value field
- how to save multiple custom fields for a post in one go?
- Get aggregate list of all custom fields for entire blog
- get_post_meta in sitewide tags plugin fails to return value for custom fields
- Best way to add custom / magic / flutter fields into RSS feed