Hello,
This is php with wordpress question...
add_action( 'save_post', 'ces_meta_box_save' );
function ces_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;
// This is purely my personal preference for saving check-boxes
$chk = isset( $_POST['features_module'] ) ? 'on' : 'off';
update_post_meta( $post_id, 'features_module', $chk );
}
function display_features_module() {
global $chk;
if ($chk == 'on') { // also tried using $_Post[$chk]
echo '<style type="text/css"> #featured_post { display:none !important; }</style>';
}
}
add_action('wp_head','display_features_module');
I am basically just trying to change styles based on $chk variable -which should have "on" or "off" value. It's saving but I can't get it to display the correct styles. When it's set above (in the save function), it's always showing "off" so I am guessing it's not saving this value/i'm doing something wrong...
anyone have any advice?
thank u!