You are not including any previously set values in the input
field.
$value = get_post_meta($post_id->ID,'event-link',true);
<input type="text" style="padding:10px;" value="'.$value.'" name="event-link"/>
Note that the meta box callback get a post object not just an ID.
Additionally, you are not saving your fields at all. Instead you are saving either 1
or 0
. If you want to save your fields you can’t just save a pseudo-boolean.
The third parameter of update_post_meta
is the value you want to save. You need:
if ( isset( $_POST['event-date'] ) )
update_post_meta( $post_id, 'event-date', $_POST['event-date'] );
else
update_post_meta( $post_id, 'event-date', 0 );
Please look into data sanitization though.
Third, you are not getting past the nonce check.
wp_nonce_field
looks like this:
wp_nonce_field( $action, $name, $referer, $echo );
wp_verify_nonce
looks like this:
wp_verify_nonce( $nonce, $action );
What you need is :
wp_nonce_field( 'myplugin_nonce_action', 'myplugin_nonce' );
And :
// security check
if ( !wp_verify_nonce( $_POST['myplugin_nonce'], 'myplugin_nonce_action' ) )
return;
Finally, you need to pass $post_id
into your save_post
callback.
function event_details_data($post_id) {
Now it works.