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!
<?php
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' );
?>
<p>
<input type="radio" name="linktype" value="freedownload_album" <?php echo ($radio); ?>/> Free<br />
<input type="radio" name="linktype" value="buyonitunes_album" <?php echo ($radio); ?>/> iTunes<br />
<input type="radio" name="linktype" value="none_album" <?php echo ($radio); ?>/> None<br />
</p>
<?php
}
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 ) );
}
?>
EDIT #1
Seems to be working great now, thank you for the help!
Only problem now as I mentioned is its not showing which radio button has been selected after hitting publish...(see below)
EDIT #2
Also curious how it may be possible to output the "pretty version" of each inputs value for my custom columns so that they appear like - "iTunes", rather then "buyonitunes_album".
EDIT #3
No big deal if this isnt possible, but is there any way to potentially make the values appear neater for the columns? ie. "freedownload_album" -> "Free", for example. (See below)
This is how Im currently outputting the value to my columns...
function eprmusicrelease_custom_columns($column){
global $post;
switch ($column)
{
case "albumthumb":
if (has_post_thumbnail($post->ID))
echo get_the_post_thumbnail($post->ID, 'music-release-img-col');
else
echo 'No Image Available';
break;
case "albumlink":
if (get_post_meta($post->ID, 'meta_box_musicreleases_url', true))
echo make_clickable (get_post_meta ($post->ID, 'meta_box_musicreleases_url', true));
else
echo 'No URL Chosen';
break;
case "linktype":
echo get_post_meta($post->ID, 'meta_box_musicreleases_linktype', true);
break;
case 'author':
echo get_post_meta( $post->ID , 'author' , true );
break;
case 'date':
echo get_post_meta( $post->ID , 'date' , true );
break;
}
}
?>