You can use the save_post
hook.
add_action( 'save_post', 'mytheme_my_post_just_updated' );
function mytheme_my_post_just_updated($post_id){
$deal_type = get_field($post_id, 'deal_type');
if($deal_type == 'sold'){
$gallery = get_field($post_id, 'gallery');// This bit and the next few lines will depend on how you've set up the custom field.
// Fast forward a few lines...
foreach($images as $image){ // I'm assuming that $images is an array of attachment_ids, but will depend on how you've used ACF to create the custom field
wp_delete_attachment($image, true); // args are attachment_id and whether or not to bypass trash.
}
}
}
Put the above code into your theme’s functions.php
.
More on wp_delete_attachment()
– https://codex.wordpress.org/Function_Reference/wp_delete_attachment
Related Posts:
- Remove Dimension from wp_get_attachment_image
- Add multiple images to a page sidebar
- Add custom field to image editor
- Display info from custom fields in all images’ HTML
- automatically set “Featured Image” the same as the og:i that is set in a custom field
- copy attachments to another post type and change attachment url
- How can I store a file in the database in the same way WordPress and ACF do?
- Add new image block, set default class name and update it using Javascript
- How to get custom image field of specific post id
- Shortcode for Custom Field of Media Attachment (to use with Featured Images)
- Adding thumbnails for non-image attachments
- Add image custom attribute [closed]
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- Where are custom field values stored in the database
- Advanced Custom Fields – Get custom fields from parent page
- Add custom field to the archive page?
- Matching Serialized Arrays with meta_query
- explode array within shortcode
- How can I append custom data to images in the editor?
- How to position a custom field before the editor
- Change wp_get_attachment_image attributes (src and srcset) on specific custom field
- How do I make a custom field choose an image?
- Display post_object content using Advanced Custom Fields plugin
- How can I remove fields in the attachment editor?
- Remove old custom field after import
- Unable to get Preview of Uploaded image within a Custom Meta box
- Extend WP Customizer to make multiple image selection possible
- Saving Custom Field in Attachment Window in WordPress 3.5
- Retrieve custom fields on Categories, using WP-API
- How to set a default meta value for custom field
- Order by custom field date?
- Display thumbnail from custom field
- How to save custom fields for attachments
- Change content before writing to database
- Order Custom post type loop by custom field (datepicker)
- Using Custom Function With Advanced Custom Fields
- Stopping WordPress from Auto Generating Image Files for Sizes
- limit amount of photos uploaded per cpt post
- ajax delete value from custom field array
- Problem with adding exta field in metabox in custom post type
- Save attachment custom fields on front end
- Copying Custom Meta Values from existing post to a duplicate post
- Calculate the sum of certain the_sub_fields
- Displaying Custom Fields on Post with Genesis Child Theme
- Metabox with multiple fields added by user and upload box
- Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
- Login & Register & Custom details WITHOUT plugin
- Send Multiple Custom Field Values Through the URL
- ACF won’t load from a custom JSON location
- Add WYSIWYG to Image Description field
- Insert attachment ID in custom field from media uploader
- Get Meta from Custom Field of Image URL
- Show ACF fields only on certain page in the backend
- Add url from Custom Field as ‘Featured Image’. Code not working
- Update posts after populating ACF field value [closed]
- How can I pass a variable set by ACF to header.php?
- WP Custom Fields Metabox Disappears – ACF plugin issue [closed]
- Transfer self made functions.php custom fields to Advanced Custom Fields [closed]
- ACF: How to get the full field name (meta_key) by a field key?
- Dynamically fill a post custom field with post publish date
- Will loading too many ACF Fields cause slow down?
- How to display multiple images in custom field
- WP_User_Query pulling ACF to loop
- How to add image attachment to post from a single meta key (Woocommerce)
- Getting the ID of any image for use in functions.php
- Exclude images uploaded via meta boxes from WordPress gallery
- Validate data on attachment_fields_to_save
- How do i save and retrieve custom attachment meta?
- Custom field not updating when value is empty
- How to add the image URL from an external RSS feed and insert into a custom field?
- Calling the “wp-link-wrap” pop-up modal
- Print custom field in Query Loop block
- How to add Advenced Custom Fields In Single Post
- How to schedule a custom field value update?
- how to upload a image from frontend with wp_insert_post and also update_post_meta?
- Order RSS content by an advanced custom field value
- Get an advanced custom field after post publish
- How to create a dropdown select of all items in an ACF field group
- Better way to save image in custom field
- Advanced Custom Fields dynamic update_field
- How do I add an image upload, custom field to a WooCommerce product?
- How to use thumbnail size of image if I’m only using src to get image
- WooCommerce – Adding Custom Fields To Invoice
- Sort custom post type by multiple custom fields
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- Select multiple images from custom field
- Redirect to another page using contact form 7? [closed]
- Vimeo thumbnails
- Advanced Custom Fields WYSIWYG More tag
- Displaying page image in the footer automatically
- Walker class for sub-menu with ACF fields
- Get image url using image id
- How to list Category list in ACF Pro’s Select Field to choose from [closed]
- Link FROM attachment to full post and get custom fields values on attachment page?
- Get all the posts where meta field with multiple choice has several values checked
- Show image if author meta (profile fields) exists outside loop
- Custom fields issue [closed]
- Querying posts by latitude and longitude to build a Google Maps with several markers
- Attach images to posts using custom fields (just paths to images already uploaded)
- Convert attachment ID into url?