Custom Meta Box Values
-
Hello,
I have created a custom meta box for a check box. The meta value is posting to the database but the value in the post is not being reflected as to what is written in the database.
What am I doing wrong? Here is my code
function upaf_em_meta_boxes() { add_meta_box('em_smartcard_box', 'Is This a SMART Card Event?', 'em_smartcard_box', EM_POST_TYPE_EVENT, 'side', 'high'); } add_action('add_meta_boxes', 'upaf_em_meta_boxes'); function em_smartcard_box() { global $EM_Event; $input = ''; $input .= '<label>'; $input .= '<input type="checkbox" name="smartcardevent" value="Yes" />'; $input .= ' Yes</label><br>'; echo $input; } add_filter('em_event_save', 'upaf_em_smartcard_box_save', 1,2); function upaf_em_smartcard_box_save($result,$EM_Event) { global $wpdb; if( $result && !empty($_POST['smartcardevent']) ){ $is_sc_event = $_POST['smartcardevent']; $sc_event = "({$EM_Event->id}, 'sc_event', '$is_sc_event')"; $wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->id}' AND meta_key='sc_event'"); $wpdb->query("INSERT INTO ".EM_META_TABLE." (object_id, meta_key, meta_value) VALUES ".$sc_event); } elseif( $result && empty($_POST['smartcardevent']) ){ $is_sc_event = $_POST['smartcardevent']; $sc_event = "({$EM_Event->id}, 'sc_event', '$is_sc_event')"; $wpdb->query("DELETE FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->id}' AND meta_key='sc_event'"); $wpdb->query("INSERT INTO ".EM_META_TABLE." (object_id, meta_key, meta_value) VALUES ".$sc_event); } return $result; } function upaf_em_smartcard_box_load($EM_Event){ global $wpdb; $EM_Event->sc_event = $wpdb->get_col("SELECT meta_value FROM ".EM_META_TABLE." WHERE object_id='{$EM_Event->event_id}' AND meta_key='sc_event'", 0); } add_action('em_event', 'upaf_em_smartcard_box_load');
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom Meta Box Values’ is closed to new replies.