Why is save_post hook not running?

I am trying to save my meta box, I have something like

function xxx_meta_box_callback() {
    add_meta_box('xxx-meta', 'xxx Details', 'xxx_meta_box', 'xxx-post-type', 'side', 'default');
    add_action('save_post', 'xxx_save_meta_box');
    error_log('meta box cb');
}

function xxx_save_meta_box($post_id, $post) {
    error_log('running ...');
    die('OK!!!');
}   

I am getting “meta box cb” ok in my error log, but xxx_save_meta_box() does not seem to run. Why is that?

1 Answer
1

Try this in your theme’s functions.php file, or a .php file of a plugin that you may be writing:

add_action('save_post', 'xxx_save_meta_box');
function xxx_meta_box_callback() {
  add_meta_box('xxx-meta','xxx Details','xxx_meta_box','xxx-post-type','side','default');
  error_log('meta box cb');
}
function xxx_save_meta_box($post_id, $post) {
  error_log('running ...');
  die('OK!!!');
}   

Leave a Comment