jasonaburton
jasonaburton

Reputation: 3103

delete_post hook in Wordpress not working

add_action( 'delete_post', 'test_function' );
function test_function(){
    echo "Hello!";
}

The "Hello!" isn't showing up when I delete a post (It is a custom post-type, but that shouldn't matter right?). How do I debug this?

EDIT: I can't put that code in any front-end files like header.php or index.php because I won't be able to view the output when I delete a post from the back-end. What's the best way to tackle this?

Thanks

Upvotes: 2

Views: 5126

Answers (1)

Hampton Paulk
Hampton Paulk

Reputation: 187

Try doing the following to see if you are reaching your filter. I tested this here with 3.2.1 and it works fine for me.

function test_function(){
    die('deleted post');
}

this action will not run until you delete the post from the trash. If you want it to run when you move it to the trash the action is 'trash_post'.

Upvotes: 6

Related Questions