Since you are using this code in the shortcode, I suppose the reason is the lack of post ID.
You want to get the ID of the current post from the $post
variable, but to make it possible you need to add the global $post;
earlier (at the beginning of the function, or at least before the IF
).
global $post;
if ( isset( $_POST['zon_testimonial_nonce'] ) &&
wp_verify_nonce($_POST['zon_testimonial_nonce'],'zon_testimonial') )
You can also use the get_queried_object_id()
function to get the ID of the current queried object.
$post_id = get_queried_object_id();
if ( isset( $_POST['zon_testimonial_nonce'] ) &&
wp_verify_nonce($_POST['zon_testimonial_nonce'],'zon_testimonial') )
{
$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);