0

I have looked at both the delete_post and before_delete_posts. Neither of these hooks actually allow me to perform a check and then tell wordpress not to delete the post. Anyone got any ideas?

1 Answer 1

0

You can hook into before_delete_post and redirect before completing the deletion.

add_action('before_delete_post', function($post_id) {

   // Get custom field
   $field = get_post_meta( $post_id, 'key', 'true');

   // Redirect if field is empty
   if (!$field) {
       wp_redirect(admin_url('edit.php'));
       exit();
   }

}, 1);
1
  • Thanks I will check this out when I get to working on those functions. I must have been up late that night or misunderstood something or maybe it was the fact I didn't know redirecting would solve the problem. It makes perfect sense so I'm accepting it before hand. Wordpress makes developing a dream. Commented Dec 13, 2013 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.