WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

I created a meta box I notice that save_post seems to be triggered when I land on the page, thus giving me errors like Undefined index: xxx in /data/www/ae/wp-content/themes/xx/functions.php on line 121

add_action('save_post', function($id) {
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
    if (!isset($_POST) || !is_array($_POST)) {
    update_post_meta($id, 'xxx', sprintf('%f', $_POST['xxx']));
share|improve this question
up vote 3 down vote accepted

See Why does save_post action fire when creating a new post?

You're getting the error as you need to check for the existence of $_POST['xxx'], rather than just checking if $_POST is set (it will always be set & an empty array by default).

add_action('save_post', function($id) {
    if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) || !isset( $_POST['xxx'] ) )

    update_post_meta( $id, 'xxx', sprintf( '%f', $_POST['xxx'] ) );
    // run further code
share|improve this answer

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.