Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this action/hook:

add_action( 'before_delete_post', 'my_delete_function' );
 function my_delete_function($post_id) { 
    global $wpdb;
    $achievement = get_the_category($post_id); 
    $h = $achievement[0]->cat_ID; 
    $s = ''.str_replace('"', '', $h);
   if ( $s == 6 || $s == 5){
        $wpdb->query("DELETE FROM wp_votes WHERE post = ".$post_id) or die(mysql_error());

    }
}

The above works great when I am deleting posts from the admin. However, when the wp_delete_post() is called, the action doesnt work.

How can I make the action work with the delete function?

share|improve this question

1 Answer 1

wp_delete_post() always triggers before_delete_post - the problem must be that you're hooking your function conditionally (i.e. not all the time).

before_delete_post only gets triggered if you're actually deleting the post permanently, not just trashing it.

If you need to listen for trashing too, use wp_trash_post.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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