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)?
- Custom post meta field effect on the performance on the post
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- What is “meta_input” parameter in wp_insert_post() used for?
- How to enable revisions for post meta data?
- Add custom objects/entities to WordPress
- How can I append custom data to images in the editor?
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- Filter results with custom field values and dropdown
- passing argument to get_template_part() or a better way to code
- How to set a default meta value for custom field
- Is there a way to do multiple ordering on a multiple meta_query?
- Create meta boxes that don’t show in custom fields
- Ordering posts by anniversary using only day and month
- Adding Properties to User Profile and Displaying in List
- How to use pagination with get_post_meta
- How to get custom field image url of specific size
- Custom fields: In what order are they saved into the DB?
- Custom field value based on other custom field values
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How to display Meta Field Value?
- MySQL query to set wp_postmeta using term_taxonomy_id value
- How to Validate Post Meta type/extension (Video File Image File etc)
- Custom Meta Box not Saving in Posts with Gutenberg Editor
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- How to wrap meta values seperated by comma in ? [closed]
- Bulk remove post meta
- How to create html block to display extra information on woocommerce single product page
- Better Method for Multiple Meta Boxes
- Run a check for multiple meta key values
- Getting the ID of any image for use in functions.php
- custom avatar removal
- WordPress Rest API to call page data associate with custom meta
- Send email with custom fields after new draft is saved or new post published
- Hide custom meta data if empty
- How to create a shortcode to print specific values stored in a post meta array?
- Add custom field to all posts in specific post_type
- Button inside Custom Meta Box triggering the Update Button
- How to load an assets based on custom field value?
- Custom WP_Query for WordPress Search Results with meta_query
- How can you include custom post meta in search without calling each key?
- Can I access a post meta field before the loop?
- wrap text around custom fields array
- Customize rel=canonical tag for single blog post
- Get all the posts where meta field with multiple choice has several values checked
- wordpress custom loop ascending descending posts by custom field
- Hide custom fields when empty
- Check & remove special characters in a field?
- Save all the post tags inside a custom field
- if in category but only with post meta
- How add multiple wp_editor_box to new post
- Update post meta custom field using block editor
- Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle
- Get YouTube video id from url in a custom field
- Related query shows same image in loop
- Why am I getting a “Call to member function format() on a non-object” error?
- Can’t Output get_post_meta?
- Modify custom field from front end
- How to get all custom fields with some prefix in key?
- WP-eComerce Advance Meta Tag data in descending order [closed]
- Custom Query: query by post custom meta data
- get_post_custom_values problem, please help
- Adding re-type email and check it if the email match
- Counting post fields
- update_post_meta not working well
- Custom meta fields and meta keys
- How to add a post’s view count into the WordPress API response
- Can’t set custom meta fields for a post
- Query Posts based on custom field value
- Query postmeta values, and return multiple post_titles for common meta value
- custom field functionality
- How to add an option to admin to add image that could be used as header?
- Custom Field: Display only if a specific key is selected outside the loop
- Show or hide lang=”ur” in main element
- When editing a post with a custom meta box the values aren’t displaying correctly
- Hard Define Custom Field Value
- I would like to display different text on different pages
- add_post_meta insert null value into Database
- Add image custom attribute [closed]
- Retrieving custom field as shortcode
- Problem display
- Add fields to edit in custom widget
- save all acf options in one meta_value [closed]
- WP Query Args – search by meta_key or title
- Search for meta_query does not return any result if combined with title