add_meta_box Callback not being called

I created my first plugin last week that makes a custom post type. As this worked, I copy pasted the code I already had and modified it to be a different post type. For whatever reason however, the callback I have set for add_meta_box is not being called. Can anyone tell me why this is, where I have looked it over repeatedly with no luck what so ever.

/**
 * Adds a meta box to the post editing screen
/***************************************************************************/
function package_custom_meta()
{
    add_meta_box( 'package_meta', __( 'Package Title', 'package_textdomain' ), 'package_meta_callback', 'package' , 'high' );

    echo "package_custom_meta CALLED";
}

add_action( 'add_meta_boxes', 'package_custom_meta' );

/**
 * Outputs the content of the meta box
/***************************************************************************/
function package_meta_callback( $post )
{
    echo "package_meta_callback CALLED";

    wp_nonce_field( basename( __FILE__ ), 'package_nonce' );
    $package_stored_meta = get_post_meta( $post->ID );
    ?>

    <p>
        <label for="meta-package-512mb" class="package-row-title"><?php _e( '512MB RAM', 'package_textdomain' )?></label>
        <input type="text" name="meta-package-512mb" id="meta-package-512mb" value="<?php if ( isset ( $package_stored_meta['meta-package-512mb'] ) ) echo $package_stored_meta['meta-package-512mb'][0]; ?>" />
    </p>

    <p>
        <label for="meta-package-1gb" class="package-row-title"><?php _e( '1GB RAM', 'package_textdomain' )?></label>
        <input type="text" name="meta-package-1gb" id="meta-package-1gb" value="<?php if ( isset ( $package_stored_meta['meta-package-1gb'] ) ) echo $package_stored_meta['meta-package-1gb'][0]; ?>" />
    </p>

    <?php
}

2 Answers
2

Looks like we both missed the error because I didn’t see it at first either.

In your call to add_meta_box you skipped the argument for context and went straight to priority. “high” is not an available string for the context argument, and this apparently causes the function to silently fail.

Adding in the string for context fixes it:

add_meta_box( 'package_meta', __( 'Package Title', 'package_textdomain' ), 'package_meta_callback', 'package', 'normal', 'high' );

Leave a Comment