Can I delete images permanently (from the custom field image on the edit page) without having to go into the media manager?
Thanks
Hi @pjeaje
By default, no.
However, you could hook into the image update_value action and look for an empty value. If found, you could lookup the old value (get_field) and then use the ID to remove it from the DB completely.
You can target all image update_value actions like so:
function my_acf_update_value( $value, $post_id, $field )
{
// do something else to the $post object via the $post_id
return $value;
}
add_filter('acf/update_value/type=image', 'my_acf_update_value', 10, 3);
Learn more:
http://www.advancedcustomfields.com/resources/filters/acfupdate_value/
This reply has been marked as private.
Hi @pjeaje
No, the above code will not delete images.
It is a demonstration of how you can hook into the update_value filter and delete it with code.
Please remember that this is a support forum, not a free development service. I can point you in the right direction with functions, docs and general help, but I will not write your custom code for you.
Thanks
E
Please remember that this is a support forum, not a free development service.
Thanks I never forgot, I was just asking as i didn’t know what the code did.
Do we have to use a specific field name for this, to get the previous value? I mean does this apply: get_field($field, $post_id)
or we have to specify a field name like this ‘get_field(‘field_name’, $post_id)’. could you possibly write this tutorial, it would be much appreciated. Anyone found a solution on this?