Home › Forums › General Issues › ACF Form Delete Post › Reply To: ACF Form Delete Post
add_filter('acf/save_post', 'possibly_delete_post');
function possibly_delete_post($post_id) {
$post_type = get_post_type($post_id);
// change to post type you want them to be able to delete
if ($post_type != 'post-type') {
return;
}
if (get_field('delete_this_post', $post_id)) {
$force_delete = false; // move to trash
// change above to true to permanently delete
wp_delete_post($post_id, $force_delete);
// redirect them somewhere since the post will no longer exist
// see https://developer.wordpress.org/reference/functions/wp_redirect/
wp_redirect('/some_page/');
exit;
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.