Support » How-To and Troubleshooting » Custom “radio button meta box” not saving correctly

Custom “radio button meta box” not saving correctly

  • I’m having trouble with my “custom meta box/write panel” script that contains radio buttons. (see below)…It currently does not seem to save the selection made after publishing the custom post type, not sure what Ive missed???

    How I plan to utilize this essentially is by letting the client choose one of the radio button choices, and depending on what selection is made I will output that as a class into an anchor tag to help instantiate a specific image overlay.

    Thank you for your help!

    add_action( 'add_meta_boxes', 'musicreleases_linktype_meta_box_add' );
    function musicreleases_linktype_meta_box_add()
        add_meta_box( 'musicreleases_linktype_meta_id', 'Link Type (Optional)', 'musicreleases_linktype_meta_box_cb', 'eprmusicrelease', 'normal', 'low' );
    function musicreleases_linktype_meta_box_cb( $post )
        $values = get_post_custom( $post->ID );
        $radio = isset( $values['meta_box_musicreleases_linktype'] ) ? esc_attr( $values['meta_box_musicreleases_linktype'][0] ) : '';
        wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
            <input type="radio" name="linktype" value="free" <?php echo ($radio); ?>/> Free<br />
            <input type="radio" name="linktype" value="itunes" <?php echo ($radio); ?>/> iTunes<br />
            <input type="radio" name="linktype" value="none" <?php echo ($radio); ?>/> None<br />
    add_action( 'save_post', 'musicreleases_linktype_meta_box_save' );
    function musicreleases_linktype_meta_box_save( $post_id )
        if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
        if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
        if( !current_user_can( 'edit_post' ) ) return;
        $allowed = array(
            'a' => array(
                'href' => array()
        if( isset( $_POST['meta_box_musicreleases_linktype'] ) )
            update_post_meta( $post_id, 'meta_box_musicreleases_linktype', wp_kses( $_POST['meta_box_musicreleases_linktype'], $allowed ) );
  • The topic ‘Custom “radio button meta box” not saving correctly’ is closed to new replies.