How to delete attachments associated with custom field type when post property changes? [closed]

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 … Read more