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

I recently switched themes and copied over my metaboxes from the old functions.php into the new one. They show up but when I click publish/edit they dont save

add_action( 'add_meta_boxes', 'cd_meta_box_add' );

function cd_meta_box_add() {
    add_meta_box( 'my-meta-box-id', 'Video', 'omc_video_encode', 'post', 'normal', 'high' );
    add_meta_box( 'my-meta-box-id-a', 'Audio', 'omc_audio_encode', 'post', 'normal', 'high' );
    add_meta_box( 'my-meta-box-id-d', 'Download', 'download_link', 'post', 'normal', 'high' );

function omc_video_encode() {
    <label for="omc_video_encode">Iframe here.</label>  
    <input style="width: 500px;" type="text" name="omc_video_encode" id="omc_video_encode" />  

function omc_audio_encode() {
    <label for="omc_audio_encode">Jwplayer here.</label>  
    <input style="width: 500px;" type="text" name="omc_audio_encode" id="omc_audio_encode" />  

function download_link() {
    <label for="download_link">Link here.</label>  
    <input style="width: 500px;" type="text" name="download_link" id="download_link" />  

add_action( 'save_post', 'cd_meta_box_save' );

function cd_meta_box_save( $post_id ) {
    // Bail if we're doing an auto save  
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    // if our nonce isn't there, or we can't verify it, bail 
    if ( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) )
    // if our current user can't edit this post, bail  
    if ( !current_user_can( 'edit_post' ) )
share|improve this question
I checked the link but im still a bit confused, do i add $nonce= wp_create_nonce ('meta_box_nonce'); ? and where – user2145837 Apr 11 '13 at 2:15

You don't appear to be setting meta_box_nonce anywhere in your code. As your cd_meta_box_save function returns if the nonce isn't set, your fields will not be saved.

See the codex for more on nonces.

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.