WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Thank you for reading,

I added custom fields to the comment form, and saved the input in the DB, following this tutorial http://wp.smashingmagazine.com/2012/05/08/adding-custom-fields-in-wordpress-comment-form/comment-page-1/#comment-115187

Now i'd like the meta-fields in the comment form to auto-fill after the user has commented once.

Just like wordpress does with the Name, E-mail and Url; once you've commented the value stays in the fields. However, wordpress does this with $commenter['comment_author'] and this array doesn't have the data I'm looking for.

share|improve this question
up vote 2 down vote accepted

You can store these values in cookies and fill them when you are creating form inputs.

So in save_comment_meta_data add something like this:

$commenter_data = array(
  'phone' => $phone,
setcookie('commenter_data', serialize($commenter_data), time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);

And then when you're creating form:

$commenter_data = isset($_COOKIE['commenter_data']) ? unserialize($_COOKIE['commenter_data]) : array();
echo '<p class="comment-form-title">'.
'<label for="phone">' . __( 'Commenter Phone' ) . '</label>'.
'<input id="phone" name="phone" type="text" size="30"  tabindex="5" value="'. (array_key_exists('phone', $commenter_data) ? $commenter_data['phone'] : '') .'" /></p>';
share|improve this answer
This code wasn't tested so it can be a little bit buggy, I guess. But the idea behind it should be clear. – Krzysiek Dróżdż Jun 19 '13 at 19:53
I was hoping to do it with WP's functions. But I guess cookies will do as fine. Thanks a lot for the reply! – sanchy Jun 20 '13 at 10:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.