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 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?

share|improve this question
2  
Why are you adding the save_posts callback from inside the metabox callback? I'd take a guess at that being the issue. –  t31os Apr 6 '11 at 11:15

1 Answer 1

up vote 6 down vote accepted

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!!!');
}   
share|improve this answer
    
Why does add_action('save_post' have to be on wp init? –  NoBugs Nov 3 at 6:35
    
It actually does not. When I answered this question I misunderstood this aspect of WordPress. I'm editing my answer. –  MikeSchinkel Nov 3 at 15:09

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.