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 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" />  
    <?php
}

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" />  
    <?php
}

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

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 )
        return;
    // 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' ) )
        return;
    // if our current user can't edit this post, bail  
    if ( !current_user_can( 'edit_post' ) )
        return;
}
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
    

1 Answer 1

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

 
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.