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]
- 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 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
- 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
- ajax delete value from custom field array
- Save attachment custom fields on front end
- 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
- Get Meta from Custom Field of Image URL
- Update posts after populating ACF field value [closed]
- WP Custom Fields Metabox Disappears – ACF plugin issue [closed]
- Transfer self made functions.php custom fields to Advanced Custom Fields [closed]
- Will loading too many ACF Fields cause slow down?
- Validate data on attachment_fields_to_save
- Custom field not updating when value is empty
- Calling the “wp-link-wrap” pop-up modal
- 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
- 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
- Select multiple images from custom field
- Redirect to another page using contact form 7? [closed]
- Advanced Custom Fields WYSIWYG More tag
- 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?
- 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)
- How to copy data from a custom field to the post_content?
- ul list with only as many li’s as filled custom fields
- Display custom field from the front page on another page
- Custom field as featured image caption
- How to Pass values to Custom Field through PHP in WordPress Posts?
- Filter posts by custom field (Advanced Custom Fields)
- How can I output the custom fields wrapping with HTML
- Displaying an ACF list of users
- The conditional logic only works to show or hide?
- ACF Plugin How to make the customer add more fields in the post?
- Selectively hiding or allowing thumbnails of featured images on front page
- wp_get_attachment_image_src() with advanced custom fields returning empty
- Unable to select image with custom field
- Users uploaded image and matching an id or taxonomy
- How To Save Data From Remote APIs To ACF?
- comments_where Hook
- Rewrite comment form post ID on submit
- How to show ACF fields in Gridbuilder custom block
- Problem with revisions only returning four results
- How to set up page fields with gutenberg instead of ACF
- ACF multi taxonomy on filterable gallery
- Is there any way to make a custom field for a post only if the author is a certain user?
- How to use ACF with javascript to update custom field values?
- Get list of posts from attachment
- adding autosave feature to custom fields
- Getting user’s data, by custom field lookup (meta)
- Counting number of images from loop
- Page template is missing fields or is invalid when I updating the template
- Advanced Custom Fields from Category – IF statement
- Display Child Page with custom fields within Parent Page
- WordPress taxonomy child image
- Filter and display a specific custom field value [closed]
- Change path to child of page when uploading image via custom field
- Query Posts Via WordPress URL
- Upload image to wordpress
- I want to add a custom field in the rss title of each post, but don’t want it to be shown on the site
- Update field name without losing the value
- Get single image from custom fields made with WCK custom fields creator
- How to get all specific fields from one ACF Group?
- save all acf options in one meta_value [closed]
- acf field repeater link don’t work
- ACF in radio button cf7