How I can update Existing (Back-End) metabox variable from front-End, I tried many times but I don't know why doesn't this work? Showing only old value not update, what i did wrong?
This is my Front-End Page, I'm using this code inside normal Page With shortCode and also this code between post loop.
if ( isset( $_POST['zon_testimonial_nonce'] ) && wp_verify_nonce($_POST['zon_testimonial_nonce'],'zon_testimonial') )
{ //if nonce check succeeds.
$post_id = $post->ID;
$data = array(
'package' => sanitize_text_field( $_POST['zon_package'] )
);
update_post_meta( $post_id, '_zon_testimonial_key', $data );
}
$data = get_post_meta($post->ID, '_zon_testimonial_key', true);
$package = isset($data['package']) ? $data['package'] : '';
print_r($_POST);
?>
<form method="post" action="">
<?php wp_nonce_field('zon_testimonial','zon_testimonial_nonce'); ?>
<label>This is label</label>
<input type='text' name='zon_package' value='<?php echo $package; ?>' />
<input type='submit' value='save' />
</form>
update_post_meta()
and displaying form) is in the same place / file?global $post;
, saves and reads the data correctly. Enable debugging in WP. Check value of post ID and$data
beforeupdate_post_meta
:echo "id={$post_id}, data= " . print_r($data, true);