I have added a custom post page option but it's not working; the output is always empty.
I have this debug code in my loop (the code that retrieves the information in frontend):
$colorvalue = get_post_meta( get_the_ID(), 'slider_is_dark', 1 );
echo '<script>alert("' . $colorvalue . '");</script>';
Then I have this in my functions.php:
add_action( 'add_meta_boxes', 'slider_checkboxes' );
function slider_checkboxes() {
add_meta_box(
'slider',
'Slider',
'slider_box_content',
'post',
'normal',
'default'
);
}
function slider_box_content( $post_id ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'slider_nonce' );
echo '<input type="checkbox" name="slider_is_dark" value="1" /> Slider is dark';
}
add_action( 'save_post', 'slider_data' );
function slider_data() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !wp_verify_nonce( $_POST['slider_nonce'], plugin_basename( __FILE__ ) ) )
return;
if ( isset( $_POST['slider_is_dark'] ) )
update_post_meta( $post_id, 'slider_is_dark', 1 );
else
update_post_meta( $post_id, 'slider_is_dark', 0 );
}
The alert always returns empty. Is there a problem in my code or am I doing it wrong?