WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Info about wp_die from codex: Kill WordPress execution and display HTML message with error message. A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.

I have code:

function myHook( $post_ID, $post )
     wp_die('Error', 'Error',  array( 'response' => 500, 'back_link' => true ));
add_action( 'save_post', 'myHook', 0, 2 );

Problem is that error page appears, but post is still inserted. Shouldn't saving be interrupted by this hook? If I misunderstood description, how can I break execution so post will not be saved?

EDIT: I just found that save_post is called after instert to database not before. Does there exist any function called before insert that i can hook into?

Thanks in advance

share|improve this question

Try filtering with wp_insert_post_data instead. It's from wp-includes/post.php, line 2864.

add_filter( 'wp_insert_post_data', 'post_publish_filter_wpse_82356' );
function post_publish_filter_wpse_82356( $data ) {
    // view/manipulate $data
    if ('publish' == $data['post_status']) {
        $msg = '<pre>' . var_export($data, true) . '</pre>';
    return $data;

publish is the post_status when you click the Publish or Update button. The four statuses I've found are:

  • auto-draft - self-explanatory (also, status is set to this when you click Add New)
  • draft - when you click Save Draft button
  • inherit - when you click Preview button
  • publish - when you click Publish or Update button
share|improve this answer
According to codex it works only for updates. It's not called on inserts. – user1666774 Jan 20 '13 at 8:36
@user1666774: See my updated Answer. – akTed Jan 20 '13 at 8:43
Problem is that in this filter i don't have access to data from add_meta_box – user1666774 Jan 20 '13 at 9:13
See my updated (again - I've finally tested enough, hopefully no more edits :) ) answer for the statuses I've found and updated example code. Regarding add_meta_box data, that'll have to be another Question. – akTed Jan 20 '13 at 9:24
It's possible you can find the add_meta_box data in one of WP's global variables or pull it from a function call. – akTed Jan 20 '13 at 9:29

Your Answer


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.