Front end update_post_meta Help
I followed the help provided in this question but cannot get the form save
the data. I tried using 'save_post' action hook to try and save the post
like we do for admin side. Any help would be highly appreciated.
My code is as below:
/* This is above the get_header() of the template */
if ( isset( $_POST['grn_data'] ) &&
wp_verify_nonce($_POST['grn_data'],'update_grn_postmeta') )
{ //if nonce check succeeds.
global $post;
$postid = $post->ID;
$data = $_POST['grn'];
update_post_meta($postid,'grn',$data);
}
And the form is in a seperate file and i am calling it whenever it is
necessary.
<?php
/* This file is to provide input fields to record data from Front End */
function grn_data($c) {
global $post;
$grn = array();
?>
<div class="grndata">
<label for="grn" id="grnhead">GRN</label>
<div class="toggle-fedata">
<ul>
<?php
$curgrn = 'grn';
$grnval = get_post_meta($post->ID, $curgrn, true); ?>
<form method="post" action="">
<?php wp_nonce_field('update_grn_data','grn_data'); ?>
<input type="text" size="30" maxlength="30" name="<?php echo
$curgrn; ?>" value="<?php echo $grnval; ?>" />
<input type="submit" value="Save" />
<?php var_dump($grnval); ?>
<?php var_dump($curgrn); ?>
</form>
</div></div>
<?php }
?>
Please can someone advise on this? I have been stuck like this for days now.
No comments:
Post a Comment