0

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;
}
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.